$(function () { var $qrcode = document.url $('.phone .img').qrcode({ render: "canvas", // 二维码生成方式 text: $qrcode, // 二维码内容 width: "108", // 二维码的宽度 height: "108", }); var right = $(".bottom .right"), left = $(".bottom .left"); nexttop = $('.content .box .next')[0].offsettop $(window).scroll(function () { var lheight = left.outerheight(); var rheight = right.outerheight(); var top = $(document).scrolltop(); var leftpos = left.offset().top; var plusheith = (lheight + leftpos) - rheight; console.log(top - (lheight + leftpos) + rheight) if (top >= leftpos) { if (right.css("position") == "absolute") { right.css({ "position": "fixed", "top": "0px", }); } if (right.css("position") == "fixed") { if (top >= plusheith) { right.css({ 'position': 'absolute', 'top': lheight - rheight }); } } } else { if (right.css("position") == "fixed") right.css({ "position": "absolute", "top": "0px", }); } // console.log(lheight) // $(".bottom .right-box").css('height', lheight) // if (top > rightpos) { // right.css({ // 'position': 'fixed', // }); // // if ((top - (lheight + leftpos) + rheight) > 0) { // // right.css({ // // 'position': 'absolute', // // 'top': 'auto', // // 'bottom': '0' // // }); // // } // } else { // right.css({ // 'position': 'absolute', // }); // } }); })