简体   繁体   English

div内div的固定位置

[英]fixed position for a div inside a div

i was working on woocommerce site. 我在woocommerce网站上工作。 My Site . 我的网站 The single product page has a control generator with a number of drop down options.So when a user selects each options he cannot see the changes happening at the top.So i position the image div as fixed.As follows. 单个产品页面具有一个控件生成器,该控件生成器具有许多下拉选项。因此,当用户选择每个选项时,他看不到顶部发生的更改。

.single-product .images{position:fixed;}

this made the image fixed but it is floating till down the page.I only need it just before the description/review tabs starts.Is there any other css or any js/jquery solutions to solve this .Please help.Thanks!! 这使图像固定,但它一直浮动到页面。我只需要在描述/评论选项卡开始之前就需要它。是否有任何其他的CSS或任何js / jquery解决方案来解决这个问题。请帮助。谢谢!

Based on your website environment, you need something like this: 根据您的网站环境,您需要以下内容:

var images = jQuery('.images');

jQuery.fn.followTo = function (pos) {
    var $this = this,
        $window = jQuery(window);

    $window.scroll(function (e) {
        if ($window.scrollTop() > pos) {
            $this.css({
                position: 'absolute',
                top: pos - $this.height()
            });
        } else {
            $this.css({
                position: 'fixed',
                top: 'auto' //earlier it was 0
            });
        }
    });
};

images.followTo(jQuery('#myTab').offset().top - images.height());

You may need to re-position the elements a bit, but the script will work on your website, as I tested with firebug. 您可能需要稍微重新定位元素,但是该脚本将在您的网站上正常运行,正如我使用firebug测试的那样。

I have note written this script, the script attributed to: Stopping fixed position scrolling at a certain point? 我已记下此脚本,该脚本归因于: 在某个点停止固定位置滚动?

Let me know if you can take it forward from here :) 让我知道您是否可以从这里继续前进:)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM