1 . Code Js này có chức năng làm gì zậy ?
2 . Code js này có chức năng làm gì zậy ?
Ai biết trả lời cho em 2 js trên có cung dụng làm gì nha các a
- Code:
/**
* jQuery.ScrollTo
* Copyright (c) 2007-2009 Ariel Flesler - aflesler(at)gmail(dot)com | http://flesler.blogspot.com
* Dual licensed under MIT and GPL.
* Date: 5/25/2009
*/
;(function( $ ){
var $scrollTo = $.scrollTo = function( target, duration, settings ){
$(window).scrollTo( target, duration, settings );
};
$scrollTo.defaults = {
axis:'xy',
duration: parseFloat($.fn.jquery) >= 1.3 ? 0 : 1
};
// Returns the element that needs to be animated to scroll the window.
// Kept for backwards compatibility (specially for localScroll & serialScroll)
$scrollTo.window = function( scope ){
return $(window)._scrollable();
};
// Returns the real elements to scroll (supports window/iframes, documents and regular nodes)
$.fn._scrollable = function(){
return this.map(function(){
var elem = this,
isWin = !elem.nodeName || $.inArray( elem.nodeName.toLowerCase(), ['iframe','#document','html','body'] ) != -1;
if( !isWin )
return elem;
var doc = (elem.contentWindow || elem).document || elem.ownerDocument || elem;
return $.browser.safari || doc.compatMode == 'BackCompat' ?
doc.body :
doc.documentElement;
});
};
$.fn.scrollTo = function( target, duration, settings ){
if( typeof duration == 'object' ){
settings = duration;
duration = 0;
}
if( typeof settings == 'function' )
settings = { onAfter:settings };
if( target == 'max' )
target = 9e9;
settings = $.extend( {}, $scrollTo.defaults, settings );
// Speed is still recognized for backwards compatibility
duration = duration || settings.speed || settings.duration;
// Make sure the settings are given right
settings.queue = settings.queue && settings.axis.length > 1;
if( settings.queue )
// Let's keep the overall duration
duration /= 2;
settings.offset = both( settings.offset );
settings.over = both( settings.over );
return this._scrollable().each(function(){
var elem = this,
$elem = $(elem),
targ = target, toff, attr = {},
win = $elem.is('html,body');
switch( typeof targ ){
// A number will pass the regex
case 'number':
case 'string':
if( /^([+-]=)?\d+(\.\d+)?(px|%)?$/.test(targ) ){
targ = both( targ );
// We are done
break;
}
// Relative selector, no break!
targ = $(targ,this);
case 'object':
// DOMElement / jQuery
if( targ.is || targ.style )
// Get the real position of the target
toff = (targ = $(targ)).offset();
}
$.each( settings.axis.split(''), function( i, axis ){
var Pos = axis == 'x' ? 'Left' : 'Top',
pos = Pos.toLowerCase(),
key = 'scroll' + Pos,
old = elem[key],
max = $scrollTo.max(elem, axis);
if( toff ){// jQuery / DOMElement
attr[key] = toff[pos] + ( win ? 0 : old - $elem.offset()[pos] );
// If it's a dom element, reduce the margin
if( settings.margin ){
attr[key] -= parseInt(targ.css('margin'+Pos)) || 0;
attr[key] -= parseInt(targ.css('border'+Pos+'Width')) || 0;
}
attr[key] += settings.offset[pos] || 0;
if( settings.over[pos] )
// Scroll to a fraction of its width/height
attr[key] += targ[axis=='x'?'width':'height']() * settings.over[pos];
}else{
var val = targ[pos];
// Handle percentage values
attr[key] = val.slice && val.slice(-1) == '%' ?
parseFloat(val) / 100 * max
: val;
}
// Number or 'number'
if( /^\d+$/.test(attr[key]) )
// Check the limits
attr[key] = attr[key] <= 0 ? 0 : Math.min( attr[key], max );
// Queueing axes
if( !i && settings.queue ){
// Don't waste time animating, if there's no need.
if( old != attr[key] )
// Intermediate animation
animate( settings.onAfterFirst );
// Don't animate this axis again in the next iteration.
delete attr[key];
}
});
animate( settings.onAfter );
function animate( callback ){
$elem.animate( attr, duration, settings.easing, callback && function(){
callback.call(this, target, settings);
});
};
}).end();
};
// Max scrolling position, works on quirks mode
// It only fails (not too badly) on IE, quirks mode.
$scrollTo.max = function( elem, axis ){
var Dim = axis == 'x' ? 'Width' : 'Height',
scroll = 'scroll'+Dim;
if( !$(elem).is('html,body') )
return elem[scroll] - $(elem)[Dim.toLowerCase()]();
var size = 'client' + Dim,
html = elem.ownerDocument.documentElement,
body = elem.ownerDocument.body;
return Math.max( html[scroll], body[scroll] )
- Math.min( html[size] , body[size] );
};
function both( val ){
return typeof val == 'object' ? val : { top:val, left:val };
};
})( jQuery );
2 . Code js này có chức năng làm gì zậy ?
- Code:
$(document).ready(function() {
$(window).scroll(function(){
var scrollTop=((window.scrollY-0));
if ( $(this).scrollTop() < 102 ){
$("nav, .left-side_nav").css('top',(102-(scrollTop))).removeClass('justthumb');
$("nav #mesg_noti").slideUp('fast');
$("#chat_hangout, .full_hangout").css('top',146);
} if ( $(this).scrollTop() > 102 ){
$("nav, .left-side_nav").css('top',0).addClass('justthumb');
$("nav #mesg_noti").slideDown('fast');
$("#user_panel").fadeOut('fast');
$(".full_hangout").css('top',44);
} if ( $(this).scrollTop() < 352 ){
$("header").removeClass('small_info').parent().css('padding-top',0);
$("#jump_top").fadeOut('fast');
} if ( $(this).scrollTop() > 352 ){
$("header").addClass('small_info').parent().css('padding-top',354);
$("#jump_top").fadeIn('fast');
}
});
});
$(document).ready(function() {
var curlink = location.href;
if ((curlink.indexOf('wall') > -1) && (curlink.indexOf('u') > -1)) {
var rdt=curlink.replace("wall","");
location.href=rdt;
} if ((curlink.indexOf('stats') > -1) && (curlink.indexOf('u') > -1)) {
var rdt=curlink.replace("stats","");
location.href=rdt;
} if ((curlink.indexOf('friends') > -1) && (curlink.indexOf('u') > -1)) {
var rdt=curlink.replace("friends","");
location.href=rdt;
} if ((curlink.indexOf('contact') > -1) && (curlink.indexOf('u') > -1)) {
var rdt=curlink.replace("contact","");
location.href=rdt;
} if (curlink.indexOf('?tt=1') > -1) {
var gulink = curlink.replace("?tt=1","");
} else {
var gulink = curlink;
}
var wheight = document.documentElement.clientHeight;
$("#nav_current").hover(function() {
$('.left-side_nav').animate({left:'0px'},100);
});
$(".left-side_nav").hover(function() {
$('.left-side_nav').animate({left:'0px'},100);
}, function(){
$('.left-side_nav').animate({left:'-270px'},100);
});
$(".g_search_box").submit(function(e) {
var keyword = $(this).children('input#g_search_input').val();
$("#gkw").html(keyword);
if (keyword != '') {
$('.search_rs_box').show();
$(this).children('input#g_search_input').removeClass('error').focus()
} else {
$('.search_rs_box').hide();
$(this).children('input#g_search_input').addClass('error').focus();
}
$(".put_the_rs").empty();
$(".search_rs_box").append('<div id="no_rs_box" class="still_loading nodis">Đang tìm...</div>');
$('.still_loading').fadeIn('fast');
$.get("/search?search_keywords="+keyword, function(data) {
$(data).find(".statused").children().appendTo(".put_the_rs");
$(".still_loading").fadeOut("slow", function() {
$(this).remove();
if ($(".put_the_rs").html() == '') {
$(".put_the_rs").append('<div id="no_rs_box">Không có kết quả cho từ khoá '+keyword+'!</div>');
}
});
$(".put_the_rs tr").children(".tc2,.tcr").remove();
$(".put_the_rs tr .tcl").children("img").remove();
$(".put_the_rs tr").children(".tc3").prepend(' - ');
$(".put_the_rs tr").children(".tc3:last-child").prev('.tc3').append(' trả lời');
$(".put_the_rs tr").children(".tc3:last-child").append(' lượt xem');
});
return false;
});
$('#close_srch').live("click",function(){
$('.search_rs_box').fadeOut('fast',function(){
$(".put_the_rs").empty();
});
});
$("#turn_chat, #close_hangout").live("click", function() {
$("#chat_hangout").toggle().removeClass("full_hangout");
});
$("#full_hangout").live("click", function() {
var scrollTop=((window.scrollY-0));
$("#chat_hangout").toggleClass("full_hangout").removeClass("hide_hangout");
if (scrollTop > 102) {
$("#chat_hangout").css('top',146);
$(".full_hangout").css('top',44);
} else {
$("#chat_hangout").css('top',146);
}
});
$("#hide_hangout").live("click", function() {
$("#chat_hangout").toggleClass("hide_hangout");
if ($("#chat_hangout").hasClass("hide_hangout")) {
$("#chat_hangout").css('top',(wheight-39)).removeClass("full_hangout");
} else {
$("#chat_hangout").css('top',146);
}
});
$("#show_s_option").live("click", function() {
$("#stream_option").fadeToggle('fast');
});
$("#stream_option .str_button").live("click", function() {
$("#stream_option .str_button").removeClass("active");
$("#stream_option").fadeOut('fast');
$(this).addClass("active");
});
$(".str_button.tscol").live("click", function() {
$("#wrapper").removeClass("ocolonly");
});
$(".str_button.oscol").live("click", function() {
$("#wrapper").addClass("ocolonly");
});
$("#gt_ava").live("click", function() {
$("#user_panel").fadeToggle('fast');
});
$(".collapse_boxes").live("click",function() {
$(this).children("b").toggle();
$(this).parent().parent(".boxes").children("#all_boxes").slideToggle();
});
$("#control_m_tab span").live("click", function() {
var datam = $(this).attr("data-module");
var label = $(this).text();
var cdatam = $(".a_box.current_tab").attr("data-module");
var clabel = $(".a_box.current_tab #abox_descript h3 span").text();
$(".a_box.current_tab #abox_descript h3 span").html(label);
$(".a_box.current_tab").attr("data-module",datam);
$("#control_m_tab").append('<span data-module="'+cdatam+'">'+clabel+'</span>');
$(this).remove();
var taken = $(datam+" .content_to_take").html();
$(".a_box.current_tab .current_content").html(taken);
});
$("#profile_username").live("mouseover",function() {
$(this).children(".profile_box").fadeIn("fast");
});
$("#profile_username").live("mouseleave",function() {
$(this).children(".profile_box").hide();
});
$('strong').each(function(i) {
if ($(this).html() == "Advanced Search") {
$(this).html("Tìm kiếm nâng cao");
}
});
if ($("title").html() == "Advanced Search") {
$("title").html("Tìm kiếm nâng cao");
}
$(".glogin").live("click",function() {
$(".g_login_panel").toggle();
$("body").toggleClass("noscroll");
});
$('input[value="gcover_photo"]').attr('value','gcover_photo').hide();
$('.profile_box img[alt="gcover_photo"]').each(function(i) {
var gcover = $(this).attr("src");
$(this).parent().parent(".profile_box").children("#pcover_box").css("background-image","url("+gcover+")");
$(this).parent().remove();
});
$('#profile-advanced-left img[alt="gcover_photo"]').each(function(i) {
var gcover = $(this).attr("src");
$('header').css("background-image","url("+gcover+")");
$(this).parent().parent().parent().next('.separator').remove();
$(this).parent().parent().parent().remove();
$(".center_nav li.active").html('<a direction="#goto_profile">Lý lịch</a>');
$(".center_nav li.active").after('<li><a direction="#goto_wall"><span>Tường</span></a></li><li><a direction="#goto_stats"><span>Thống kê</span></a></li><li><a direction="#goto_cont"><span>Liên hệ</span></a></li><li><a direction="#goto_friend"><span>Bạn bè</span></a></li>');
$('.center_nav li.activetab').remove();
$('.center_nav a[href="/#goto_stats"],.center_nav a#show_s_option,#profile-advanced-left #tabs').parent().remove();
});
$("#profile-advanced-layout").prepend('<a class="fake_pos" id="goto_profile"></a>');
$('#profile-advanced-right').each(function(i) {
if ($('#profile-advanced-add').length > 0) {
var gusername = $(this).children("#profile-advanced-add").next(".module").children('.main-head').children('.h3').html();
$('#n-site_infom h1').html('<a href="'+gulink+'">'+gusername+'</a>');
var guserava = $(this).children("#profile-advanced-add").next(".module").children('.main-head').next('.main-content').children('img:first').attr("src");
$('#n-site_logo img').attr('src',guserava);
$(this).children("#profile-advanced-add").next(".module").remove();
$(this).children("#profile-advanced-add").children('br').remove();
$(this).children("#profile-advanced-add").children('a').after(' ');
$(this).children("#profile-advanced-add").children('a').addClass('button').addClass('flat');
$(this).children("#profile-advanced-add").children('a:last').addClass('red');
var guadd = $(this).children("#profile-advanced-add").html();
$('#n-site_infom p').html('Thành viên của diễn đàn!<br/>'+guadd);
} else {
var gusername = $(this).children(".module:first").children('.main-head').children('.h3').html();
$('#n-site_infom h1').html('<a href="'+gulink+'">'+gusername+'</a>');
var guserava = $(this).children(".module:first").children('.main-head').next('.main-content').children('img:first').attr("src");
$('#n-site_logo img').attr('src',guserava);
$(this).children(".module:first").remove();
$('#n-site_infom p').html('Thành viên của diễn đàn!');
}
var fr_temp = $(this).children(".module:last").html();
$("#profile-advanced-left").append('<div id="pmd_wall" class="gfriend_module"><div class="main-head"><a class="fake_pos" id="goto_wall"></a>Tường</div></div><div id="pmd_stats" class="gfriend_module"><div class="main-head"><a class="fake_pos" id="goto_stats"></a>Thống kê</div></div><div id="pmd_cont" class="gfriend_module"><div class="main-head"><a class="fake_pos" id="goto_cont"></a>Liên hệ</div></div><div class="gfriend_module"><a class="fake_pos" id="goto_friend"></a>'+fr_temp+'</div>');
$(this).children(".module:last").remove();
$.get(gulink+"wall", function(data) {
$(data).find("#profile-advanced-details:first").appendTo("#pmd_wall");
$(".new-message a").addClass('button flat blue').html('Gửi tin nhắn mới').css('margin-bottom',10);
});
$.get(gulink+"stats", function(data) {
$(data).find("#profile-advanced-details:first").appendTo("#pmd_stats");
});
$.get(gulink+"contact", function(data) {
$(data).find("#profile-advanced-details:first").appendTo("#pmd_cont");
});
});
$('a').each(function(i) {
if ($(this).html() == "Add to my friends list") {
$(this).html("Thêm bạn");
} if ($(this).html() == "Add to my foes list") {
$(this).html("Thêm thù");
}
});
$('#gquickreply .frm-buttons input[type="submit"]').addClass('flat');
$('#gquickreply .frm-buttons input[value="Send"]').attr('value','Trả lời').addClass('blue');
$(".posting [href*='/privmsg?mode=post']").addClass('button flat blue').html('Gửi tin nhắn mới');
});
jQuery(document).ready(function($) {
$('*').click(function () {
$('body').scrollTo($(this).attr('direction'), 600);
return false;
});
});
Ai biết trả lời cho em 2 js trên có cung dụng làm gì nha các a