jquery一些使用技巧

1.jquery描点平滑定位

// 定义将要去的描点位置

var pos = $("#limit_top").offset().top;

// 实现平滑移动 1000代表时间ms

$("html,body").animate({scrollTop: pos}, 1000);

ps:有人问怎么用?

在js里面写入上面的语句就好了。(需要用到jquery框架,懂得人都明白吧。)

第一句就是定义将要跳到的地方,#limit_top 你要跳到的描点位置标识,只要改这个就好

第二句就是定义跳的过程的时间,1000 是指1秒钟。

2.ajax向后台发json格式的请求数据

$(function(){
	$('button').click(function(){
		var jsonObj = {
				name: "通知列表",
				description: "本文描述",
				terminals: [{type: "EMail", content: "[email protected]", verified: false}]
			};
		var jsonStr = JSON.stringify(jsonObj);
		
		$.ajax({
			url: '${pageContext.request.contextPath}/notification-lists/new',
			type: 'POST',
			contentType: 'application/json;charset=UTF-8',
			dataType: 'json',
			data: jsonStr,
			success: function(data){
				console.info(data);
			}
		})
	});
});

3.获取最大的z-index

//获取页面最大z-index
function getMaxZindex(){
	var maxZ = Math.max.apply(null, $.map($('.window'), function (e, n) {
        if ($(e).css('position') == 'absolute')
            return parseInt($(e).css('z-index')) || 1;
        })
    );
    return maxZ;
}

 

猜你喜欢

转载自shuizhongyue.iteye.com/blog/2269559