2016-04-29 99 views
0

这里我试图从jQuery向左移动一个div。我写的js部分工作。我可以在Chrome,Opera和Yandex浏览器的某些页面中按预期(从左到右)移动div,但在firefox中根本无法工作,所以我相信实现并不合格,并且必须有更多具体而有效的方式。使用下面的代码片段,一个div(一个类似于弹出窗口的fb)出现,几秒钟后显示页面加载,效果是将div从左向右滑动。有一个关闭按钮。点击关闭按钮后,div缩回(现在从右到左效果)。为了便于充分理解,我给出了完整的代码风格。你提供给我的任何见解都会有很大的帮助。谢谢。 (JS代码在后面给出)滑动div从左到右只能部分与jquery工作

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script> 
 
<div class = "modal-prompt modal-prompt-shown" id = "fb_like" style = "display: none; z-index: 10000; width: 100%; height: 100%; position: absolute; top: 0px; left: 0px;"> 
 
    <style> 
 
    .modal-overlay { 
 
     /* overflow-y: scroll; */ 
 
     position: fixed; 
 
     top: 0; 
 
     left: 0; 
 
     width: 100%; 
 
     height: 100%; 
 
     z-index: 10000; 
 
     background-color: rgba(0, 0, 0, 0.5); 
 
     /* dim the background */ 
 
     cursor: pointer; 
 
    } 
 

 
    .modal-close-half-page { 
 
     background: none; 
 
     color: white; 
 
     font-weight: bold; 
 
     position: fixed; 
 
     right: 50px; 
 
     font-size: 14px; 
 
    } 
 

 
    .modal-prompt-half-page { 
 
     display: block; 
 
     height: 100%; 
 
     position: fixed; 
 
     width: 50%; 
 
     background-color: #1fc2ff; 
 
     top: 0; 
 
     left: 0; 
 
     z-index: 1000000; 
 
    } 
 

 
    .modal-prompt-half-page-arrow { 
 
     width: 0; 
 
     height: 0; 
 
     border-top: 30px solid transparent; 
 
     border-bottom: 30px solid transparent; 
 
     border-left: 30px solid #1fc2ff; 
 
     position: absolute; 
 
     top: 50%; 
 
     right: -30px; 
 
     margin-top: -30px; 
 
    } 
 

 
    .modal-prompt-half-page-header { 
 
     font-weight: bold; 
 
     font-size: 57px; 
 
     padding: 0 40px; 
 
     text-align: right; 
 
     line-height: 58px; 
 
     color: white; 
 
     text-transform: inherit; 
 
     top: 50%; 
 
     position: absolute; 
 
     -webkit-transform: translateY(-50%); 
 
     -ms-transform: translateY(-50%); 
 
     transform: translateY(-50%); 
 
     margin-bottom: 0; 
 
    } 
 

 
    .social-prompt-button-facebook { 
 
     width: 101px; 
 
     height: 101px; 
 
     -moz-border-radius: 101px; 
 
     -webkit-border-radius: 101px; 
 
     border-radius: 101px; 
 
     background-color: white; 
 
     position: absolute; 
 
     left: 110%; 
 
     top: 50%; 
 
     margin-top: -51px; 
 
    } 
 

 
    .social-prompt-button-facebook .fb-like { 
 
     position: absolute; 
 
     top: 50%; 
 
     left: 50%; 
 
     margin-top: -10px; 
 
     margin-left: -24px; 
 
    } 
 

 
    .modal-prompt-half-page { 
 
     left: calc(-40% - 30px); 
 
     transition: left 0.4s ease; 
 
     width: 40%; 
 
     min-width: 450px; 
 
    } 
 

 
    .modal-overlay { 
 
     opacity: 0; 
 
     transition: opacity 0.4s ease; 
 
     top: 0; 
 
    } 
 

 
    .social-prompt-button-facebook { 
 
     overflow: hidden; 
 
     position: fixed; 
 
     top: 0; 
 
     bottom: 0; 
 
     left: calc(40% + 60px); 
 
     margin: auto 0; 
 
     width: 101px; 
 
     height: 101px; 
 
     -webkit-transform: scale(0); 
 
     -moz-transform: scale(0); 
 
     -ms-transform: scale(0); 
 
     -o-transform: scale(0); 
 
     transform: scale(0); 
 
     transition: height 0.4s ease, width 0.4s ease, transform 0.4s ease; 
 
    } 
 

 
    .modal-copy-container{ 
 
     font-size: 5vw; 
 
     line-height: 5vw; 
 
     margin-top: 0; 
 
    } 
 

 
    .modal-prompt-shown .modal-prompt-half-page { 
 
     left: 0; 
 
    } 
 

 
    .modal-prompt-shown .modal-overlay { 
 
     opacity: 1; 
 
    } 
 

 
    .modal-prompt-shown .social-prompt-button-facebook { 
 
     -webkit-transform: scale(1); 
 
     -moz-transform: scale(1); 
 
     -ms-transform: scale(1); 
 
     -o-transform: scale(1); 
 
     transform: scale(1); 
 
    } 
 

 
    @media (max-width: 1125px) { 
 
     .modal-prompt-half-page { 
 
     width: 450px; 
 
     left: -480px; 
 
     } 
 

 
     .modal-prompt-shown .modal-prompt-half-page { 
 
     left: 0; 
 
     } 
 

 
     .social-prompt-button-facebook { 
 
     left: 510px; 
 
     } 
 

 
     .modal-copy-container { 
 
     font-size: 800 normal 3.125rem/3.125rem WorkSans, sans-serif; 
 
     /* line-height: 56px; */ 
 
     } 
 
    } 
 

 
    </style> 
 
    <div class = "modal-overlay"></div> 
 
    <div class = "modal-prompt-half-page"> 
 
    <div class = "modal-close modal-close-half-page" onclick = "closeFB();">Close</div> 
 
    <h6 class = "modal-prompt-half-page-header modal-copy-container">If you liked reading this story, then Like our page!</h6> 
 
    <div class = "modal-prompt-half-page-arrow"></div> 
 
    <div class = "modal-prompt-half-page-cont clearfix"> 
 
     <div class = "social-prompt-button-facebook"> 
 
     <div class = "fb-like fb_iframe_widget" data-href = "#" data-layout = "button" data-action = "like" data-show-faces = "false" data-callback-id = "genmodalfb" data-keen-tracking-name = "newUserModalV1" data-keen-social-channel = "facebook" data-keen-custom = "Halfpage 1.32" fb-xfbml-state = "rendered" fb-iframe-plugin-query = "action=like&amp;app_id=141861192518680&amp;container_width=0&amp;href=https%3A%2F%2Fwww.facebook.com%2FMicMedia&amp;layout=button&amp;locale=en_US&amp;sdk=joey&amp;show_faces=false"> 
 
      <span style = "vertical-align: bottom; width: 49px; height: 20px;"> 
 
      <iframe name = "f1be53ad29d6424" width = "1000px" height = "1000px" frameborder = "0" allowtransparency = "true" allowfullscreen = "true" scrolling = "no" title = "fb:like Facebook Social Plugin" src = "#" class = "" style = "border: none; visibility: visible; width: 49px; height: 20px;"></iframe> 
 
      </span> 
 
     </div> 
 
     </div> 
 
    </div> 
 
    </div> 
 
</div> 
 

 
<script> 
 
    $(document).ready(function() { 
 
    setTimeout(function() { 
 
     // $('.modal-prompt').css('display', 'block').fadeIn("slow", function() {}); 
 
     $('.modal-prompt').animate({width: 'show'}); 
 
    }, 5000); 
 
    }); 
 
</script> 
 

 
<script type="text/javascript"> 
 
    $(document).ready(function() { 
 
    $(".modal-close").click(function() { 
 
     $(".modal-prompt").animate({ 
 
     width: "hide" 
 
     }); 
 
    }); 
 
    }); 
 
</script>

+2

您如何期待我们运行模态。页面打开时没有任何反应。 –

+0

@Praveen,我现在添加了jquery。现在打开。 –

回答

0

它不会在所有的工作。我不知道为什么你用这么多的代码,但是你有向左滑动做的是使用JQuery的动画功能,比如:

$('#elementId').animate({ 
       left: '50%', 
      }, 500); 

您可以为按顺序做将它从左到右,反之亦然。动画或任何东西都不需要CSS,只是基本的样式。

1

切换“隐藏”默认设置从右到左