JavaScript

超轻量级php框架startmvc

jQuery实现的简单悬浮层功能完整实例

更新时间:2020-04-21 00:27 作者:startmvc
本文实例讲述了jQuery实现的简单悬浮层功能。分享给大家供大家参考,具体如下:运行效果

本文实例讲述了jQuery实现的简单悬浮层功能。分享给大家供大家参考,具体如下:

运行效果图如下:

具体代码如下:


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Test</title>
<script type="text/javascript" language="javascript" src="jquery-1.7.2.min.js"></script>
<script type="text/javascript" language="javascript" >
$(function() {
 var timer, scrollTop, sideDiv = $('#fudong').appendTo('body');
 $(window).scroll(function() {
 timer && clearTimeout(timer);
 scrollTop = $(this).scrollTop();
 timer = setTimeout(function() {
 sideDiv.animate({
 top: scrollTop + 100 + 'px'
 }, 600);
 }, 200);
 });
});
</script>
</head>
<body >
<div id="fudong" style="border:1px solid #454545; width:150px; height:400px; position: absolute; right: 20px; top: 100px;">
 右侧悬浮层
</div>
</body>
</html>