这是b.apsx 的 js 代码 太长了,分了2段来上载 <script language="javascript" type="text/javascript"> function abc() { $(document).ready(function() { (function($) { var types = ['DOMMouseScroll', 'mousewheel']; $.event.special.mousewheel = { setup: function() { if (this.addEventListener) { for (var i = types.length; i; ) { this.addEventListener(types[--i], handler, false); } } else { this.onmousewheel = handler; } }, teardown: function() { if (this.removeEventListener) { for (var i = types.length; i; ) { this.removeEventListener(types[--i], handler, false); } } else { this.onmousewheel = null; } } }; $.fn.extend({ mousewheel: function(fn) { return fn ? this.bind("mousewheel", fn) : this.trigger("mousewheel"); }, unmousewheel: function(fn) { return this.unbind("mousewheel", fn); } }); function handler(event) { var orgEvent = event || window.event, args = [].slice.call(arguments, 1), delta = 0, returnValue = true, deltaX = 0, deltaY = 0; event = $.event.fix(orgEvent); event.type = "mousewheel"; // Old school scrollwheel delta if (event.wheelDelta) { delta = event.wheelDelta / 120; } if (event.detail) { delta = -event.detail / 3; } // New school multidimensional scroll (touchpads) deltas deltaY = delta; // Gecko if (orgEvent.axis !== undefined && orgEvent.axis === orgEvent.HORIZONTAL_AXIS) { deltaY = 0; deltaX = -1 * delta; } // Webkit if (orgEvent.wheelDeltaY !== undefined) { deltaY = orgEvent.wheelDeltaY / 120; } if (orgEvent.wheelDeltaX !== undefined) { deltaX = -1 * orgEvent.wheelDeltaX / 120; } // Add event and delta to the front of the arguments args.unshift(event, delta, deltaX, deltaY); return $.event.handle.apply(this, args); } })(jQuery); $(function() { // the element we want to apply the jScrollPane var $el = $('#jp-container').jScrollPane({ verticalGutter: -16 }), // the extension functions and options extensionPlugin = { extPluginOpts: { // speed for the fadeOut animation mouseLeaveFadeSpeed: 500, // scrollbar fades out after hovertimeout_t milliseconds hovertimeout_t: 1000, // if set to false, the scrollbar will be shown on mouseenter and hidden on mouseleave // if set to true, the same will happen, but the scrollbar will be also hidden on mouseenter after "hovertimeout_t" ms // also, it will be shown when we start to scroll and hidden when stopping useTimeout: false, // the extension only applies for devices with width > deviceWidth deviceWidth: 980 }, hovertimeout: null, // timeout to hide the scrollbar isScrollbarHover: false, // true if the mouse is over the scrollbar elementtimeout: null, // avoids showing the scrollbar when moving from inside the element to outside, passing over the scrollbar isScrolling: false, // true if scrolling addHoverFunc: function() { // run only if the window has a width bigger than deviceWidth if ($(window).width() <= this.extPluginOpts.deviceWidth) return false; var instance = this; // functions to show / hide the scrollbar $.fn.jspmouseenter = $.fn.show; $.fn.jspmouseleave = $.fn.fadeOut; // hide the jScrollPane vertical bar var $vBar = this.getContentPane().siblings('.jspVerticalBar').hide(); /* * mouseenter / mouseleave events on the main element * also scrollstart / scrollstop - @James Padolsey : http://james.padolsey.com/javascript/special-scroll-events-for-jquery/ */ $el.bind('mouseenter.jsp', function() { // show the scrollbar $vBar.stop(true, true).jspmouseenter(); if (!instance.extPluginOpts.useTimeout) return false; // hide the scrollbar after hovertimeout_t ms clearTimeout(instance.hovertimeout); instance.hovertimeout = setTimeout(function() { // if scrolling at the moment don't hide it if (!instance.isScrolling) $vBar.stop(true, true).jspmouseleave(instance.extPluginOpts.mouseLeaveFadeSpeed || 0); }, instance.extPluginOpts.hovertimeout_t); }).bind('mouseleave.jsp', function() { // hide the scrollbar if (!instance.extPluginOpts.useTimeout) $vBar.stop(true, true).jspmouseleave(instance.extPluginOpts.mouseLeaveFadeSpeed || 0); else { clearTimeout(instance.elementtimeout); if (!instance.isScrolling) $vBar.stop(true, true).jspmouseleave(instance.extPluginOpts.mouseLeaveFadeSpeed || 0); } }); if (this.extPluginOpts.useTimeout) { $el.bind('scrollstart.jsp', function() { // when scrolling show the scrollbar clearTimeout(instance.hovertimeout); instance.isScrolling = true; $vBar.stop(true, true).jspmouseenter(); }).bind('scrollstop.jsp', function() { // when stop scrolling hide the scrollbar (if not hovering it at the moment) clearTimeout(instance.hovertimeout); instance.isScrolling = false; instance.hovertimeout = setTimeout(function() { if (!instance.isScrollbarHover) $vBar.stop(true, true).jspmouseleave(instance.extPluginOpts.mouseLeaveFadeSpeed || 0); }, instance.extPluginOpts.hovertimeout_t); }); // wrap the scrollbar // we need this to be able to add the mouseenter / mouseleave events to the scrollbar var $vBarWrapper = $('<div/>').css({ position: 'absolute', left: $vBar.css('left'), top: $vBar.css('top'), right: $vBar.css('right'), bottom: $vBar.css('bottom'), width: $vBar.width(), height: $vBar.height() }).bind('mouseenter.jsp', function() { clearTimeout(instance.hovertimeout); clearTimeout(instance.elementtimeout); instance.isScrollbarHover = true; // show the scrollbar after 100 ms. // avoids showing the scrollbar when moving from inside the element to outside, passing over the scrollbar instance.elementtimeout = setTimeout(function() { $vBar.stop(true, true).jspmouseenter(); }, 100); }).bind('mouseleave.jsp', function() { // hide the scrollbar after hovertimeout_t clearTimeout(instance.hovertimeout); instance.isScrollbarHover = false; instance.hovertimeout = setTimeout(function() { // if scrolling at the moment don't hide it if (!instance.isScrolling) $vBar.stop(true, true).jspmouseleave(instance.extPluginOpts.mouseLeaveFadeSpeed || 0); }, instance.extPluginOpts.hovertimeout_t); }); $vBar.wrap($vBarWrapper); } } }, jspapi = $el.data('jsp'); $.extend(true, jspapi, extensionPlugin); jspapi.addHoverFunc(); }); }); }; </script>
你要实现 就只能A.ASPX页面把B页面的JS代码写过来 B.aspx放纯HTML代码
我有两个案例 ,其中一个加载 b页面后 , b 页面的 js 能有效果 。
另一个却不可以 。
另一个也是用同样原理 , 却失败了
是不是会有版本冲突的问题 ?
是不是把 b页面 拷贝后粘贴在指定的 div 里面 ?
是这个意思吗 ?
我把 css 和 js 代码都写在 a 页了 , 可是加载 b页(只有html) 后 ,js的效果就变样了。
我用的是vs 2008 , 求解啊 ~~
如果你要实现你所述的效果,可以在 b.aspx 页面中添加一个函数,如 initPage(),然后将原来在页面载入完成事件中执行的代码放到这个函数中,然后用如下的方式就可以了:
$('#xxx').load(url, function() { initPage(); });
请问如果a.aspx 和b.aspx 都调用了 jquery-1.8.3.min.js ,这在加载后会冲突吗?或是我只能在a.aspx 写呢?
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title> <script type="text/javascript" src="js/jquery-1.8.3.min.js"></script> <script type="text/javascript">
$(document).ready(function() {
$("#button").click(function() {
$("#changeCon").load("event.html", function() { abc(); });
});
});
</script></head>
<body>
<form id="form1" runat="server">
<input type="button" id="button" value="Click me" />
<div id="tt" style="width: 20px; height: 2000px">
<div id="changeCon">
</div>
</div>
</form>
</body>
</html>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link rel="stylesheet" type="text/css" href="css/scroll.css" />
<link rel="stylesheet" type="text/css" href="css/menu.css" /> <script type="text/javascript" src="js/jquery-1.8.3.min.js"></script> <script type="text/javascript" src="js/jquery.jscrollpane.min.js"></script> <style>
body
{
font-family: "Trebuchet MS" ,Verdana,Arial,sans-serif;
font-size: 14px;
line-height: 1.6;
margin: 0px;
}
.middle_box
{
padding: 5px;
height: 500px;
width: 978px;
position: relative;
margin-top: 20px;
margin-right: auto;
margin-bottom: auto;
margin-left: auto;
border: 1px solid #999;
-webkit-box-shadow: 2px 2px 4px 2px rgba(0, 0, 0, 1);
box-shadow: 2px 2px 4px 2px rgba(0, 0, 0, 0.5);
}
.jp-container
{
width: 976px;
height: 498px;
position: relative;
background: #fff;
float: left;
}
/*---------------------------------------*/.event_box
{
width: 960px;
height: 190px;
margin: 10px auto 20px auto;
box-shadow: 0 1px 5px rgba(0,0,0,.5);
}
.event_box img
{
margin: 10px 0 10px 10px;
float: left;
border: 1px solid #CCC;
}
.event_text
{
margin-left: 15px;
margin-top: -5px;
width: 450px;
height: 181px;
overflow: hidden;
float: left;
}
.expired
{
margin-left: 860px;
margin-top: 0px;
width: 100px;
height: 100px;
background: url(images/expired.png);
}
</style>
</head>
<body onload="abc()">
<div class="middle_box">
<div id="jp-container" class="jp-container">
<div class="event_box">
<img src="images/5.jpg" alt="" width="440" height="170" />
<div class="event_text">
<h2 style="text-decoration: underline">
h
</h2>
<p>
1
</p>
</div>
<div class="expired">
</div>
</div>
<div class="event_box">
<img src="images/5.jpg" alt="" width="440" height="170" />
<div class="event_text">
<h2 style="text-decoration: underline">
h
</h2>
<p>
e
<html>
), w
<img>. T .</p>
</div>
<div class="expired">
</div>
</div>
<div class="event_box">
<img src="images/5.jpg" alt="" width="440" height="170" />
<div class="event_text">
<h2 style="text-decoration: underline">
h
</h2>
<p>
1。
</p>
</div>
<div class="expired">
</div>
</div>
</div>
</div>
</body>
</html>
太长了,分了2段来上载 <script language="javascript" type="text/javascript">
function abc() {
$(document).ready(function() {
(function($) { var types = ['DOMMouseScroll', 'mousewheel']; $.event.special.mousewheel = {
setup: function() {
if (this.addEventListener) {
for (var i = types.length; i; ) {
this.addEventListener(types[--i], handler, false);
}
} else {
this.onmousewheel = handler;
}
}, teardown: function() {
if (this.removeEventListener) {
for (var i = types.length; i; ) {
this.removeEventListener(types[--i], handler, false);
}
} else {
this.onmousewheel = null;
}
}
}; $.fn.extend({
mousewheel: function(fn) {
return fn ? this.bind("mousewheel", fn) : this.trigger("mousewheel");
}, unmousewheel: function(fn) {
return this.unbind("mousewheel", fn);
}
});
function handler(event) {
var orgEvent = event || window.event, args = [].slice.call(arguments, 1), delta = 0, returnValue = true, deltaX = 0, deltaY = 0;
event = $.event.fix(orgEvent);
event.type = "mousewheel"; // Old school scrollwheel delta
if (event.wheelDelta) { delta = event.wheelDelta / 120; }
if (event.detail) { delta = -event.detail / 3; } // New school multidimensional scroll (touchpads) deltas
deltaY = delta; // Gecko
if (orgEvent.axis !== undefined && orgEvent.axis === orgEvent.HORIZONTAL_AXIS) {
deltaY = 0;
deltaX = -1 * delta;
} // Webkit
if (orgEvent.wheelDeltaY !== undefined) { deltaY = orgEvent.wheelDeltaY / 120; }
if (orgEvent.wheelDeltaX !== undefined) { deltaX = -1 * orgEvent.wheelDeltaX / 120; } // Add event and delta to the front of the arguments
args.unshift(event, delta, deltaX, deltaY); return $.event.handle.apply(this, args);
} })(jQuery);
$(function() { // the element we want to apply the jScrollPane
var $el = $('#jp-container').jScrollPane({
verticalGutter: -16
}), // the extension functions and options
extensionPlugin = { extPluginOpts: {
// speed for the fadeOut animation
mouseLeaveFadeSpeed: 500,
// scrollbar fades out after hovertimeout_t milliseconds
hovertimeout_t: 1000,
// if set to false, the scrollbar will be shown on mouseenter and hidden on mouseleave
// if set to true, the same will happen, but the scrollbar will be also hidden on mouseenter after "hovertimeout_t" ms
// also, it will be shown when we start to scroll and hidden when stopping
useTimeout: false,
// the extension only applies for devices with width > deviceWidth
deviceWidth: 980
},
hovertimeout: null, // timeout to hide the scrollbar
isScrollbarHover: false, // true if the mouse is over the scrollbar
elementtimeout: null, // avoids showing the scrollbar when moving from inside the element to outside, passing over the scrollbar
isScrolling: false, // true if scrolling
addHoverFunc: function() { // run only if the window has a width bigger than deviceWidth
if ($(window).width() <= this.extPluginOpts.deviceWidth) return false; var instance = this; // functions to show / hide the scrollbar
$.fn.jspmouseenter = $.fn.show;
$.fn.jspmouseleave = $.fn.fadeOut; // hide the jScrollPane vertical bar
var $vBar = this.getContentPane().siblings('.jspVerticalBar').hide(); /*
* mouseenter / mouseleave events on the main element
* also scrollstart / scrollstop - @James Padolsey : http://james.padolsey.com/javascript/special-scroll-events-for-jquery/
*/
$el.bind('mouseenter.jsp', function() { // show the scrollbar
$vBar.stop(true, true).jspmouseenter(); if (!instance.extPluginOpts.useTimeout) return false; // hide the scrollbar after hovertimeout_t ms
clearTimeout(instance.hovertimeout);
instance.hovertimeout = setTimeout(function() {
// if scrolling at the moment don't hide it
if (!instance.isScrolling)
$vBar.stop(true, true).jspmouseleave(instance.extPluginOpts.mouseLeaveFadeSpeed || 0);
}, instance.extPluginOpts.hovertimeout_t);
}).bind('mouseleave.jsp', function() { // hide the scrollbar
if (!instance.extPluginOpts.useTimeout)
$vBar.stop(true, true).jspmouseleave(instance.extPluginOpts.mouseLeaveFadeSpeed || 0);
else {
clearTimeout(instance.elementtimeout);
if (!instance.isScrolling)
$vBar.stop(true, true).jspmouseleave(instance.extPluginOpts.mouseLeaveFadeSpeed || 0);
} }); if (this.extPluginOpts.useTimeout) { $el.bind('scrollstart.jsp', function() { // when scrolling show the scrollbar
clearTimeout(instance.hovertimeout);
instance.isScrolling = true;
$vBar.stop(true, true).jspmouseenter(); }).bind('scrollstop.jsp', function() { // when stop scrolling hide the scrollbar (if not hovering it at the moment)
clearTimeout(instance.hovertimeout);
instance.isScrolling = false;
instance.hovertimeout = setTimeout(function() {
if (!instance.isScrollbarHover)
$vBar.stop(true, true).jspmouseleave(instance.extPluginOpts.mouseLeaveFadeSpeed || 0);
}, instance.extPluginOpts.hovertimeout_t); }); // wrap the scrollbar
// we need this to be able to add the mouseenter / mouseleave events to the scrollbar
var $vBarWrapper = $('<div/>').css({
position: 'absolute',
left: $vBar.css('left'),
top: $vBar.css('top'),
right: $vBar.css('right'),
bottom: $vBar.css('bottom'),
width: $vBar.width(),
height: $vBar.height()
}).bind('mouseenter.jsp', function() { clearTimeout(instance.hovertimeout);
clearTimeout(instance.elementtimeout); instance.isScrollbarHover = true; // show the scrollbar after 100 ms.
// avoids showing the scrollbar when moving from inside the element to outside, passing over the scrollbar
instance.elementtimeout = setTimeout(function() {
$vBar.stop(true, true).jspmouseenter();
}, 100); }).bind('mouseleave.jsp', function() { // hide the scrollbar after hovertimeout_t
clearTimeout(instance.hovertimeout);
instance.isScrollbarHover = false;
instance.hovertimeout = setTimeout(function() {
// if scrolling at the moment don't hide it
if (!instance.isScrolling)
$vBar.stop(true, true).jspmouseleave(instance.extPluginOpts.mouseLeaveFadeSpeed || 0);
}, instance.extPluginOpts.hovertimeout_t); }); $vBar.wrap($vBarWrapper); } } },
jspapi = $el.data('jsp');
$.extend(true, jspapi, extensionPlugin);
jspapi.addHoverFunc(); });
});
};
</script>
不是很明白你的意思
我在b.aspx body onload 执行了 function abc() ,在b.aspx 游览没问题
a.aspx 执行$("#changeCon").load("b.aspx", function() { abc(); }); 输出的画面出错
然后我把 b.aspx 的 css 先放进 a.aspx , 结果就可以了 。
不是很明白实际运行原理...求解 ! 感谢您热心的帮助!为我解决了问题 ^.^