2012-01-12 2 views
0

저는 PHP가 처음이므로 기성 스크립트를 커스터마이징하는 것은 아직 아주 어려운 일입니다.DIV가 존재하는지 보여주기 위해 PHP 커스터마이징 모듈

애니메이션 팝업 스크립트가 있습니다. 특정 스크립트를 클릭하면 현재 트리거됩니다. 또한 특정 div가 페이지에 존재할 때이 동일한 스크립트를 자동으로 트리거하고 싶습니다.

#mask는 코드에서 볼 수 있듯이 페이지 위에 검정색 반투명 ​​레이어입니다.

<a href="#" name="modal"> 

그리고 나는 그것이 자동으로 때를 실행하려고 노력 해요 :

$(document).ready(function() { 

    //select all the a tag with name equal to modal 
    $('a[name=modal]').click(function(e) { 
     //Cancel the link behavior 
     e.preventDefault(); 
     //Get the A tag 
     var id = $(this).attr('href'); 

     //Get the screen height and width 
     var maskHeight = $(document).height(); 
     var maskWidth = $(window).width(); 

     //Set height and width to mask to fill up the whole screen 
     $('#mask').css({'width':maskWidth,'height':maskHeight}); 

     //transition effect  
     $('#mask').fadeIn(1000);  
     $('#mask').fadeTo("slow",0.8); 

     //Get the window height and width 
     var winH = $(window).height(); 
     var winW = $(window).width(); 

     //Set the popup window to center 
     $(id).css('top', winH/2-$(id).height()/2); 
     $(id).css('left', winW/2-$(id).width()/2); 

     //transition effect 
     $(id).fadeIn(2000); 

    }); 

}); 

현재는이 링크를 클릭하면 자동으로 열립니다 : 여기

내가 조정할 필요가 스크립트의 페이지에 DIV가 있습니다.

<div name="showintrovideo"></div> 

정말 고마워요. 항상 큰 도움이됩니다. -

- 앤드류

편집 여기

내가 함께 일하고 있어요 전체 코드입니다 :

HTML

<div id="boxes"> 
    <div id="qrcodemarketing" class="window"> 

     <!-- close button is defined as close class --> 
     <div style="float:right;"> 
     <a href="#" class="close"><img src="images/close_window.png" width="22"height="22" alt="Close Window" /></a> 
     </div> 

     <iframe width="640" height="480" src="http://www.youtube.com/embed/MYVIDEO" frameborder="0" allowfullscreen></iframe><br /><b>Pause the video before closing this window</b> 

    </div> 
    </div> 




    <!-- Do not remove div#mask, because you'll need it to fill the whole screen --> 
    <div id="mask"></div> 

CSS

#mask { 
    position:absolute; 
    width:100%; 
    height:100%; 
    left:0; 
    top:0; 
    z-index:9000; 
    background-color:#000; 
    display:none; 
} 

#boxes .window { 
    position:absolute; 
    background:none; 
    display:none; 
    z-index:9999; 
    padding:20px; 
    color:#fff; 
} 

의 .js는

$(document).ready(function() { 

    //select all the a tag with name equal to modal 
    $('a[name=modal]').click(function(e) { 
     //Cancel the link behavior 
     e.preventDefault(); 
     //Get the A tag 
     var id = $(this).attr('href'); 

     //Get the screen height and width 
     var maskHeight = $(document).height(); 
     var maskWidth = $(window).width(); 

     //Set height and width to mask to fill up the whole screen 
     $('#mask').css({'width':maskWidth,'height':maskHeight}); 

     //transition effect  
     $('#mask').fadeIn(1000);  
     $('#mask').fadeTo("slow",0.8); 

     //Get the window height and width 
     var winH = $(window).height(); 
     var winW = $(window).width(); 

     //Set the popup window to center 
     $(id).css('top', winH/2-$(id).height()/2); 
     $(id).css('left', winW/2-$(id).width()/2); 

     //transition effect 
     $(id).fadeIn(2000); 

    }); 


    //if close button is clicked 
    $('.window .close').click(function (e) { 
     //Cancel the link behavior 
     e.preventDefault(); 
     $('#mask, .window').hide(); 
    });  

    //if mask is clicked 
    $('#mask').click(function() { 
     $(this).hide(); 
     $('.window').hide(); 
    });   

}); 

그것은 단지의 .js 파일을 조정할 수 그것은 파일이 자동으로 열려뿐만 아니라 클릭으로도 할 수 있도록?

감사합니다.

답변

0

세션 또는 쿠키를 사용하여 소개 비디오를 표시할지 여부를 결정하는 것이 가장 좋습니다. 또한 jQuery 요소에서 호출 할 수있는 방법으로 팝업을 래핑합니다. 뭔가 같이 :

$('a').myPopupMethod(); 

그런 식으로, 당신은 또한 프로그래밍 방식으로 호출 할 수 있습니다 :

$.myPopupMethod(); 

을 HTML 페이지에서, 당신은 다음 팝업 여부를 표시할지 여부를 결정하기 위해 PHP를 사용할 수 있습니다

<?php 
    session_start(); 

    $video_watched = $_SESSION['video_watched']; 
?> 
<!DOCTYPE html> 
<html> 
    <body> 
    <script src="jquery.js"></script> 
<?php if ($video_watched != true): ?> 
    <script> 
     $(document).ready(function() { 
      $.myPopupMethod(); 
     }); 
    </script> 
<?php endif; ?> 
    </body> 
</html> 
+0

솔루션을 제공해 주셔서 감사합니다, Martin! 다시 말해서 나는 신인이기 때문에 자동 시작과 오픈 바이크 모두에서 작동하도록 조정할 수있는 방법을 알기 위해 전체 소스 코드 (질문에 추가 한)를 살펴 보시겠습니까? 솔루션 통합 방법을 모르겠습니다. 내 단점을 용서해주십시오. 건배! – Andrew

관련 문제