<script type="text/javascript">
(function($){
var ele_fix = $("#div_right"); //浮動窗口
var _main = $(".main"); //浮動區域
var ele_offset_top = ele_fix.offset().top; //浮動區域高度
$(window).scroll(function(){
var scro_top = $(this).scrollTop(); //當前高度
var fix_foot_pos = parseInt(ele_fix.height())+parseInt(scro_top)-10; //浮動框最底部到最頂部高度
var mainpos = parseInt(_main.offset().top)+parseInt(_main.height());
if(scro_top <= ele_offset_top&&fix_foot_pos<mainpos){
ele_fix.css({position: "static", top: -10});
}else if(scro_top>ele_offset_top&&fix_foot_pos<mainpos){
ele_fix.css({position: "fixed", top: -10});
}else if(scro_top>ele_offset_top&&fix_foot_pos>mainpos){
var posi = mainpos-fix_foot_pos-10;
ele_fix.css({position: "fixed", top: posi});
}
});
/*
//方案二
$(window).bind("scroll",function() {
var temp = '1165';
//判斷往下滾
if ($(document).scrollTop() > temp) { //如果大於這個高度,就置頂
flag = false;
$('#div_right').css({'position':'fixed', 'top':'-10px', 'margin-top':'0px'});
}
if ($(document).scrollTop() <= temp) { //如果小於這個高度,則恢復原來狀態
flag = true;
$('#div_right').css('position','');
}
});
*/
})(jQuery);
</script>