jquery float div开发实例
2012-06-09 17:58
169 查看
具体的功能要求是这样的:
有一个div块,应该随着鼠标向下拉,向下
参考:
http://www.mkyong.com/jquery/mashable-floating-effect-example-with-jquery/ http://www.mkyong.com/wp-content/uploads/jQuery/jQuery-Mashable-floating-effect-example.html
有一个div块,应该随着鼠标向下拉,向下
<style type="text/css"> #floating-box{ float:right; margin-left:720px; margin-right:10px; position:absolute; z-index:1; } </style> <script type="text/javascript"> //avoid conflict with other script $(document).ready(function($) { $(".circlelist ul li").click(function(){ var href = $(this).children("span").children("a").attr("href"); window.location = href; }); var $floatingbox = $('#floating-box'); if($('#body').length > 0){ var bodyY = parseInt($('#body').offset().top) - 20; var originalX = $floatingbox.css('margin-left'); $(window).scroll(function () { var scrollY = $(window).scrollTop(); var isfixed = $floatingbox.css('position') == 'fixed'; if($floatingbox.height() + 100 < $(window).height()){ if($floatingbox.length > 0){ if ( scrollY > bodyY && !isfixed ) { $floatingbox.stop().css({ position: 'fixed', left: '50%', top: 20, marginLeft: 240 }); } else if ( scrollY < bodyY && isfixed ) { $floatingbox.css({ position: 'fixed', left: '50%', top: 118, marginLeft: 240 }); } } } }); } }); </script>
参考:
http://www.mkyong.com/jquery/mashable-floating-effect-example-with-jquery/ http://www.mkyong.com/wp-content/uploads/jQuery/jQuery-Mashable-floating-effect-example.html
相关文章推荐
- 使用jQuery实现两个div中按钮互换位置的实例代码
- jQuery实现点击DIV同时点击CheckBox,并为DIV上背景色的实例
- jQuery实现div随意拖动的实例代码(通用代码)
- JQuery显示隐藏DIV的方法及代码实例
- jquery网页开发实例精解--焦点图(图片自动滚动以及鼠标经过滚动、图片自动淡入淡出已经鼠标经过淡入淡出)
- jquery实现可拖动DIV自定义保存到数据的实例
- Jquery为DIV添加click事件的简单实例
- Jquery中把一段html代码动态写入到DIV中(简单实例)
- jQuery插件开发实例
- jQuery实现的Div窗口震动效果实例
- 一个简单的jQuery插件开发实例
- jQuery 开发之EasyUI 添加数据的实例
- JS、JQuery、CSS+DIV实例大全
- JQuery实现DIV其他动画效果的简单实例
- 天猫首页迷思之-jquery实现整个div的懒加载(2)-插件面向对象化-闭包和原型的实例
- Ajax_jquery_struts_json组合开发实例
- jquery mobile + html5 手机app表单跨域提交实例(手机app开发html5 juqery moblie phonegap系列一)
- jQuery圆形统计图开发实例
- Jquery为DIV添加click事件的简单实例