我目前有一大堆jQuery函数用于我目前正在进行的网站。我不是一个真正的jQuery'ninja'(我终于开始阅读这个网站点书了)所以我确信这段代码可能写得很糟糕,可能会更清洁,更精简和更精简。
这是代码 -
// add hasJS to html to allow for CSS fallbacks
jQuery(function($) {
$('html').addClass('hasJS');
});
// ENDS
// show/hide/kill the upload files modal box
$('.upload').click(function(){
$('.uploader').toggle();
});
$('.creategroup').click(function(){
$('.createnewgroup').toggle();
return false;
});
$('.adduser').click(function(){
$('.addnewuser').toggle();
return false;
});
$('#tap-menu').click(function() {
$('#left-column, #settings, #ortibi, #userprofile').toggle();
});
$('.cancel').click(function(){
$('.uploader, .shareform').hide();
});
$('.connection-type').click(function(){
$('.connectform').toggle();
});
$('.shareit').click(function(){
$('.shareform').show();
});
$(function() {
$('article .folder-items').hide();
$("p.folder").click(function () {
$(this).parent().next(".folder-items").slideToggle("slow");
});
});
$(document).ready(function(){
$('#scrollbar1').tinyscrollbar();
});
// ENDS
$('textarea#txtarea_Message"').autoResize({
// On resize:
onResize : function() {
$(this).css({opacity:0.8});
},
// After resize:
animateCallback : function() {
$(this).css({opacity:1});
},
// Quite slow animation:
animateDuration : 300,
// More extra space:
extraSpace : 40
});
$("input:checkbox").uniform();
$("#check1").live("click", function(){
var two = $("#check2").attr("checked", this.checked);
$.uniform.update(two);
});
现在我可能在这里犯了很多错误。我该怎么做才能改进这段代码?所有帮助表示赞赏:o)
答案 0 :(得分:1)
答案 1 :(得分:1)
这样的事情?
// add hasJS to html to allow for CSS fallbacks
jQuery(function ($) {
$('html').addClass('hasJS');
$('article .folder-items').hide();
$("p.folder").click(function () { $(this).parent().next(".folder-items").slideToggle("slow"); });
$('#scrollbar1').tinyscrollbar();
});
// ENDS
// show/hide/kill the upload files modal box
$('.upload').click(function () { $('.uploader').toggle(); });
$('.creategroup').click(function (e) { e.preventDefault(); $('.createnewgroup').toggle(); });
$('.adduser').click(function (e) { e.preventDefault(); $('.addnewuser').toggle(); });
$('#tap-menu').click(function () { $('#left-column, #settings, #ortibi, #userprofile').toggle(); });
$('.cancel').click(function () { $('.uploader, .shareform').hide(); });
$('.connection-type').click(function () { $('.connectform').toggle(); });
$('.shareit').click(function () { $('.shareform').show(); });
$('textarea#txtarea_Message"').autoResize({
// On resize:
onResize: function () { $(this).css({ opacity: 0.8 }); },
// After resize:
animateCallback: function () { $(this).css({ opacity: 1 }); },
// Quite slow animation:
animateDuration: 300,
// More extra space:
extraSpace: 40
});
$("input:checkbox").uniform();
$("#check1").bind("click", function () {
var two = $("#check2").attr("checked", this.checked);
$.uniform.update(two);
});