0

我刚刚使用了 bigspotteddog 的 ScrollToFixed 插件

https://github.com/bigspotteddog/ScrollToFixed

在我的网站上

http://faiththeagency.com/easyphone/frequently-asked-questions.php) *更新的网站,所以插件工作

基本上从我可以看到这个插件直接在我的#float-cta div 下方插入一个具有这些属性的div:

<div style="width: 354px; height: 457px; float: none; display: none; "></div>

这导致我的布局发生变化和跳跃,任何人都知道为什么会这样吗?

这是我的代码。

   <div id="float-cta">

     <img src="img/phone.gif" />
     <h2>Call us on: 0800 085 2761</h2>
     <p class="f13">Lines are open 9.00am – 5.00pm,<br /> Monday to Friday.</p>

     <img src="img/store.gif" />
     <h2>Go in store</h2>
     <p class="f13">The Age UK Shop is located in Peterborough town centre: <span class="bold">25 Westgate, Peterborough, PE1 1PZ</span>. <span class="italic">Age UK Limited is acting as our<br /> in-store sales agent. All contracts are with CyCell Limited.</span></p>

     <a href="easyphone_order_form.pdf" class="block nul"><img src="img/form.gif" />
     <h2 class="ul">Download an order form</h2>
     <p class="f13">Click here to download the order form. <br />Fill it in and post it in a stamp addressed envelope to <span class="bold">EasyPhone, PO Box 70812, London, NW1W 8ZA</span></p></a>

      <img src="img/letter.gif" />
      <h2>Email order form</h2>
      <p class="f13">Scan and email your completed order form<br /> to <a href="mailto:info@cycell.com">info@cycell.com</a></p>

    </div>

jQuery

$('#float-cta').scrollToFixed();

CSS

#float-cta {
position:absolute;
width:322px;    height:395px;
background-color:#00853e;
margin: 30px 0 0 0;
color:#FFFFFF;
font-size:14px/16pt;
padding: 16px;
right:39px;
}

#float-cta.fixed {
position:fixed;
top: 0;
}

#float-cta p {
margin: 0 0 22px 52px;
}

#float-cta img {
float:left;
margin: 0 9px 0 0;
}

我会整天都在回答任何问题,并在此先感谢。

4

2 回答 2

2

所以这个问题很老了,但问题仍然存在。之前提供的解决方案只是针对特定情况的一种解决方法。

一个通用的解决方案是这样的:

  //Scroll to fixed sidebar
  $("#fixed-sidebar-wrapp").scrollToFixed();

  //Remove mystery div
  $("#fixed-sidebar-wrapp").next().remove();

假设内容修复后没有任何内容。

<div id="something">
...
</div>
<div id="sidebar">
  <div id="fixed-sidebar-wrapp"> 
    <div id="sidebar-content">
      ...
    </div>
  </div>
  <!-- Mystery div will appear here -->
</div> <!-- end sidebar --> 
<div id="more-content"> <!-- This will be unaffected by the .remove() -->

如果您在固定内容之后有一些东西,那么您当然必须相应地调整 jquery。

于 2015-06-01T08:41:57.553 回答
1

I actually contacted Bigspotteddog and he/she was very helpful with my query and supplied a fix to this problem. The fix can be seen here:

Thanks for the compliment. I found a workaround for the issue you are seeing. I don't think this plugin works well with absolutely positioned elements as it uses absolute itself.

Here is a fiddle that demonstrates the workaround: http://jsfiddle.net/duUCD/1/ (this fiddle no longer works)

Here are the changes made:

  1. Remove the marginTop from the scrollToFixed call:

    $('#float-cta').scrollToFixed();
    
  2. Put a contents wrapper (#float-cta-contents) inside of your #float-cta to create the desired margin-top:

    <div id="float-cta">
      <div id="float-cta-contents">
       ...
    
  3. Modify your css to this:

    #float-cta {
       float: right;
       margin-right:39px;
       font-family: AlwynNewRegular;
       font-size: 24px;
    }
    
    #float-cta-contents {
       width:322px;
       height:395px;
       margin-top: 30px;
       background-color:#00853e;
       color:#FFFFFF;
       padding: 16px;
    }
    
于 2012-01-23T09:56:00.020 回答