要实现一个漂浮广告效果,可以使用jQuery中的animate()方法来实现元素的动画效果。以下是一个简单的示例代码:
<!DOCTYPE html><html lang="en"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>Float Ad</title><style> #floatAd { position: fixed; bottom: 10px; right: 10px; width: 200px; height: 100px; background-color: #f00; color: #fff; text-align: center; line-height: 100px; display: none; }</style></head><body><div id="floatAd">Floating Ad</div><script src="https://code.jquery.com/jquery-3.6.0.min.js"></script><script> $(document).ready(function() { $('#floatAd').fadeIn().animate({ right: '50px', opacity: '0.7' }, 2000).animate({ right: '10px', opacity: '1' }, 2000); });</script></body></html>在上面的示例中,我们在页面中创建了一个固定位置的浮动广告元素#floatAd,初始时设置为display: none隐藏。然后在jQuery的$(document).ready()方法中,使用fadeIn()方法使元素淡入显示,然后使用animate()方法实现元素向右移动和透明度改变的动画效果。


