2015-09-08 160 views
0

试图复制一个很好看的popover我穿过网上。jQuery不适用于弹出窗口

我似乎无法让我的jQuery工作。感觉我忽略了一些明显的东西。 (但是,是我把它,是的,我在Chrome浏览资源面板双击选中)

的jsfiddle:http://jsfiddle.net/3jsrk8n8/

HTML:

<div class="scpo_overlay"></div> 
<div class="scpo_slidein"></div> 
<div class="scpo_box"> 
    <p id="scpo_title">You should really get this</p> 
    <p id="scpo_motivation">Because reasons. Undeniably good reasons</p> 
    <form action="https://www.skillcollector.com/sendy/subscribe" method="POST" accept-charset="utf-8" _lpchecked="1"> 
     <input type="text" name="email" placeholder="Email"> 
     <input type="hidden" name="list" value="lupC23UqZGvSWXHlVakRmQ" style="display:none"> 
     <input type="submit" value="Send me the eBook!" name="Get the stuff!" onclick="ga('send', 'event', { eventCategory: 'Benefits', eventAction: 'Signup', eventLabel: 'Headerwell'});"> 
    </form> 
</div> 

CSS:

 .scpo_overlay { 
      position: fixed; 
      top: 0; 
      left: 0; 
      background-color: rgba(0,0,0,0.5); 
      height: 100%; 
      width: 100%; 
      z-index: 10; 
     } 
     .scpo_slidein { 
      position: fixed; 
      top: 0; 
      left: 0; 
      background-color: red; 
      width: 55%; 
      height: 100%; 
      z-index: 11; 
     } 
     .scpo_box { 
      position: fixed; 
      right: 0; 
      left: 0; 
      top: 50%; 
      transform: translateY(-50%); 
      text-align: center; 
      width: 100%; 
      z-index: 12; 
     } 
     .scpo_box #scpo_motivation, .scpo_box form { 
      display: inline-block; 
      padding: 0 5px; 
     } 

的JavaScript:

$(function(){ 
     $('.scpo_overlay').delay(500).fadeIn(400); 
     $('.scpo_slidein').delay(700).animate({left:0}); 
     $('.scpo_box').delay(700).animate({right:0}); 
    }); 

回答

1

对于淡入工作,该元素应该被隐藏,也为左,右工作,你需要设置从那里动画应该开始适当的初始值

$('.scpo_overlay').delay(500).fadeIn(400); 
 
$('.scpo_slidein').delay(700).animate({ 
 
    left: 0 
 
}); 
 
$('.scpo_box').delay(700).animate({ 
 
    right: 0 
 
});
.scpo_overlay { 
 
    position: fixed; 
 
    top: 0; 
 
    left: 0; 
 
    background-color: rgba(0, 0, 0, 0.5); 
 
    height: 100%; 
 
    width: 100%; 
 
    z-index: 10; 
 
    display: none; 
 
} 
 
.scpo_slidein { 
 
    position: fixed; 
 
    top: 0; 
 
    left: -55%; 
 
    background-color: red; 
 
    width: 55%; 
 
    height: 100%; 
 
    z-index: 11; 
 
} 
 
.scpo_box { 
 
    position: fixed; 
 
    right: -100%; 
 
    top: 50%; 
 
    transform: translateY(-50%); 
 
    text-align: center; 
 
    width: 100%; 
 
    z-index: 12; 
 
} 
 
.scpo_box #scpo_motivation, 
 
.scpo_box form { 
 
    display: inline-block; 
 
    padding: 0 5px; 
 
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
 
<div class="scpo_overlay"></div> 
 
<div class="scpo_slidein"></div> 
 
<div class="scpo_box"> 
 
    <p id="scpo_title">You should really get this</p> 
 
    <p id="scpo_motivation">Because reasons. Undeniably good reasons</p> 
 
    <form action="" method="POST" accept-charset="utf-8" _lpchecked="1"> 
 
    <input type="text" name="email" placeholder="Email"> 
 
    <input type="hidden" name="list" value="" style="display:none"> 
 
    <input type="submit" value="Send" name="Get the stuff!"> 
 
    </form> 
 
</div>

+0

http://jsfiddle.net/3jsrk8n8/ –

+0

你先生让我的工作变得更好。谢谢! – Mentor

+0

更新,把它变成一个WordPress插件。感谢您的支持 :) – Mentor

1

你的jQuery看起来有点不合适。

同样,您应该在文档加载完成后尝试调用该函数。

<script> 
    $(document).ready(function(e){ 
     $('.scpo_overlay').delay(500).fadeIn(400); 
     $('.scpo_slidein').delay(700).animate({left:0}); 
     $('.scpo_box').delay(700).animate({right:0}); 
    }); 
</script> 
+0

我会为此表示感谢。不是$(function(){});应该是$(document).ready(function(){})的简写形式;? 编辑:它似乎还没有工作... – Mentor

+0

如果是,它的东西我还没有穿过。但有一点需要说的是采取捷径; P – TGammage

+0

另外一件事,我做的是在我的

  • 11. php file_get_contents()不能用于弹出窗口
  • 12. 弹出消息:不适用于jQuery 1.7
  • 13. scrollTop不适用于jQuery弹出框
  • 14. jquery弹出窗口自动弹出
  • 15. jquery $ .post数据从弹出窗口弹出窗口
  • 16. jquery动态弹出窗口
  • 17. jquery弹出窗口麻烦
  • 18. jquery programmatic弹出窗口
  • 19. jQuery弹出窗口滚动
  • 20. jquery html窗口弹出
  • 21. 弹出式窗口jQuery
  • 22. jQuery弹出窗口时序
  • 23. JQuery弹出窗口/菜单
  • 24. 打开弹出窗口中易于打开的弹出窗口
  • 25. 弹出窗口:当弹出弹出窗口时关闭弹出
  • 26. jquery移动弹出窗口不显示。
  • 27. JQuery弹出窗口不是呈现
  • 28. jQuery iframe弹出窗口和父窗体
  • 29. 弹出窗口不动如Facebook评论/像弹出窗口做
  • 30. 弹出窗口(不是错误弹出窗口)