<script>
$.fn.smartFloat = function() {
var position = function(element) {
var top = element.position().top, pos = element.css("position");
$(window).scroll(function() {
var scrolls = $(this).scrollTop();
if (scrolls > top) {
if (window.XMLHttpRequest) {
element.css({
position: "fixed",
top: 0
});
} else {
element.css({
top: scrolls
});
}
}else {
element.css({
position: "absolute",
top: top
});
}
});
};
return $(this).each(function() {
position($(this));
});
};
//綁定
$("#float").smartFloat();
<%if ShowRs("Item8")=2 then%>
$.fn.smartFloat1 = function() {
var position = function(element) {
var top = element.position().top, pos = element.css("position");
$(window).scroll(function() {
var scrolls = $(this).scrollTop();
if ((scrolls > top-50) && ((scrolls < $('#tourtabcont4').offset().top-100))) {
if (window.XMLHttpRequest) {
element.css({
position: "fixed",
top: 50
});
} else {
element.css({
top: scrolls
});
}
}else {
element.css({
position: "absolute",
top: top
});
}
});
};
return $(this).each(function() {
position($(this));
});
};
//綁定
$("#float1").smartFloat1();
<%end if%>
$(document).ready(function () {
$(window).scroll(function () {
var items = $(".tourcontent_20");
var menu = $(".tourcontent_17");
var top = $(document).scrollTop();
var currentId = ""; //滾動條現在所在位置的item id
items.each(function () {
var m = $(this);
//注意:m.offset().top代表每一個item的頂部位置
if (top > m.offset().top - 100) {
currentId = "#" + m.attr("id");
} else {
return false;
}
});
var currentLink = menu.find(".tourcontent_18");
if (currentId && currentLink.find("a").attr("href") != currentId) {
currentLink.removeClass("tourcontent_18");
menu.find("[href=" + currentId + "]").parent().addClass("tourcontent_18");
}
<%if ShowRs("Item8")=2 then%>
var itemss = $(".tourcontent_27");
var menus = $(".tourcontent_24");
var tops = $(document).scrollTop();
var currentIds = ""; //滾動條現在所在位置的item id
itemss.each(function () {
var ms = $(this);
//注意:m.offset().top代表每一個item的頂部位置
if (tops > ms.offset().top - 100) {
currentIds = "#" + ms.attr("id");
$(".tourcontent_24")
} else {
return false;
}
});
var currentLinks = menus.find(".tourcontent_25");
if (currentIds && currentLinks.find("a").attr("href") != currentIds) {
currentLinks.removeClass("tourcontent_25");
menus.find("[href=" + currentIds + "]").parent().addClass("tourcontent_25");
}
<%end if%>
});
});
</script>
<script type="text/javascript">
var $ = function (id) {
return "string" == typeof id ? document.getElementById(id) : id;
};
var Class = {
create: function() {
return function() {
this.initialize.apply(this, arguments);
}
}
}
var Extend = function(destination, source) {
for (var property in source) {
destination[property] = source[property];
}
return destination;
}
var Calendar = Class.create();
Calendar.prototype = {
initialize: function(container, options) {
this.Container = $(container);//容器(table結構)
this.Days = [];//日期對象列表
this.SetOptions(options);
this.Year = this.options.Year || new Date().getFullYear();
this.Month = this.options.Month || new Date().getMonth() + 1;
this.SelectDay = this.options.SelectDay ? new Date(this.options.SelectDay) : null;
this.onSelectDay = this.options.onSelectDay;
this.onToday = this.options.onToday;
this.onFinish = this.options.onFinish;
this.Draw();
},
//設置默認屬性
SetOptions: function(options) {
this.options = {//默認值
Year: 0,//顯示年
Month: 0,//顯示月
SelectDay: null,//選擇日期
onSelectDay: function(){},//在選擇日期觸發
onToday: function(){},//在當天日期觸發
onFinish: function(){}//日歷畫完後觸發
};
Extend(this.options, options || {});
},
//當前月
NowMonth: function() {
this.PreDraw(new Date());
},
//上一月
PreMonth: function() {
this.PreDraw(new Date(this.Year, this.Month - 2, 1));
},
//下一月
NextMonth: function() {
this.PreDraw(new Date(this.Year, this.Month, 1));
},
//上一年
PreYear: function() {
this.PreDraw(new Date(this.Year - 1, this.Month - 1, 1));
},
//下一年
NextYear: function() {
this.PreDraw(new Date(this.Year + 1, this.Month - 1, 1));
},
//根據日期畫日歷
PreDraw: function(date) {
//再設置屬性
this.Year = date.getFullYear(); this.Month = date.getMonth() + 1;
//重新畫日歷
this.Draw();
},
//畫日歷
Draw: function() {
//用來保存日期列表
var arr = [];
//用當月第一天在一周中的日期值作為當月離第一天的天數
for(var i = 1, firstDay = new Date(this.Year, this.Month - 1, 1).getDay(); i <= firstDay; i++){ arr.push(0); }
//用當月最後一天在一個月中的日期值作為當月的天數
for(var i = 1, monthDay = new Date(this.Year, this.Month, 0).getDate(); i <= monthDay; i++){ arr.push(i); }
//清空原來的日期對象列表
this.Days = [];
//插入日期
var frag = document.createDocumentFragment();
while(arr.length){
//每個星期插入一個tr
var row = document.createElement("tr");
//每個星期有7天
for(var i = 1; i <= 7; i++){
var cell = document.createElement("td"); cell.innerHTML = " ";
if(arr.length){
var d = arr.shift();
if(d){
cell.innerHTML = d;
this.Days[d] = cell;
var on = new Date(this.Year, this.Month - 1, d);
//判斷是否今日
this.IsSame(on, new Date()) && this.onToday(cell);
//判斷是否選擇日期
this.SelectDay && this.IsSame(on, this.SelectDay) && this.onSelectDay(cell);
}
}
row.appendChild(cell);
}
frag.appendChild(row);
}
//先清空內容再插入(ie的table不能用innerHTML)
while(this.Container.hasChildNodes()){ this.Container.removeChild(this.Container.firstChild); }
this.Container.appendChild(frag);
//附加程序
this.onFinish();
},
//判斷是否同一日
IsSame: function(d1, d2) {
return (d1.getFullYear() == d2.getFullYear() && d1.getMonth() == d2.getMonth() && d1.getDate() == d2.getDate());
}
}
</script>
這兩段js代碼放在同一個頁面中有沖突,我對js不是很熟,大家幫看看是哪裡有沖突
終於找出問題所在了,是js構造函數的$和jquery的$的沖突,把js構造函數的$換成具體的函數名就可以了,我是百度搜索到http://www.diandiba.com/News/Show.asp?ItemID=479照片文章解決的,分享給大家