我需要将一些内容加载到弹出窗口并跟随example here。它作为独立工作很好,但当我尝试使用本机jQuery v1.11.0实现到wordpress时,它不起作用。但是,它使用代码中给出的原始jquery源http://code.jquery.com/jquery-latest.pack.js
再次工作。
的Javascript
$(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 heigth 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(1000);
});
//if close button is clicked
$('.window .close').click(function (e) {
e.preventDefault(); //Cancel the link behavior
$('#mask').hide();
$('.window').hide();
});
//if mask is clicked
$('#mask').click(function () {
$(this).hide();
$('.window').hide();
});
$(window).resize(function () {
var box = $('#boxes .window');
//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});
//Get the window height and width
var winH = $(window).height();
var winW = $(window).width();
//Set the popup window to center
box.css('top', winH/2 - box.height()/2);
box.css('left', winW/2 - box.width()/2);
});
});
HTML
<a href="#dialog" name="modal">Simple Window Modal</a>
<div id="boxes">
<div id="dialog" class="window">
Simple Modal Window | <a href="#"class="close"/>Close it</a>
</div>
<div id="mask"></div><!-- Mask to cover the whole screen -->
</div><!-- end of boxes -->
任何想法如何使代码与最新的wordpress的jquery一起工作,jquery实际上是jQuery v1.11.0
,如在view-source中看到的那样。因为加载两个jquery源并没有多大意义,我希望它能与wordpress一起使用。
更新: 建议我用jQuery替换所有$并使用wp_enqueue_script和wp_register_script,我的弹出窗口按预期工作。我只需要有人来看看我如何排队脚本。这里有问题吗?
function adding_scripts() {
wp_register_script( 'my_amazing_script', get_template_directory_uri() . '/pop-stuff.js', array('jquery') );
wp_enqueue_script( 'my_amazing_script', get_template_directory_uri() . '/pop-stuff.js', array() );
}
add_action( 'wp_enqueue_scripts', 'adding_scripts' );