新聞中心
這里有您想知道的互聯(lián)網(wǎng)營(yíng)銷解決方案
前端工作中碰到的一些東西
久不出技術(shù)類文章,我都忘了自己是一程序員啦......今天寫一點(diǎn)工作中遇到的東西,大家共同學(xué)習(xí),反正也比較淺顯了。

在安圖等地區(qū),都構(gòu)建了全面的區(qū)域性戰(zhàn)略布局,加強(qiáng)發(fā)展的系統(tǒng)性、市場(chǎng)前瞻性、產(chǎn)品創(chuàng)新能力,以專注、極致的服務(wù)理念,為客戶提供成都網(wǎng)站建設(shè)、網(wǎng)站建設(shè) 網(wǎng)站設(shè)計(jì)制作按需求定制制作,公司網(wǎng)站建設(shè),企業(yè)網(wǎng)站建設(shè),品牌網(wǎng)站建設(shè),營(yíng)銷型網(wǎng)站建設(shè),成都外貿(mào)網(wǎng)站建設(shè)公司,安圖網(wǎng)站建設(shè)費(fèi)用合理。
彈出窗口
我們?cè)诠ぷ髦校?jīng)常會(huì)碰到彈出窗口類應(yīng)用,有時(shí)候還需要一點(diǎn)遮蓋層:
這類圓角彈出框其實(shí)用得還是很廣泛的,用CSS3可以很容易的出現(xiàn),但是考慮到瀏覽器兼容問(wèn)題,這類還是需要用圖片實(shí)現(xiàn)了
主要代碼如下:
- //彈出層劇中
- function popup(popupName) {
- var _scrollHeight = $(document).scrollTop(); //獲取當(dāng)前窗口距離頁(yè)面頂部高度
- _windowHeight = $(window).height(); //獲取當(dāng)前窗口高度
- _windowWidth = $(window).width(); //獲取當(dāng)前窗口寬度
- _popupHeight = popupName.height(); //獲取彈出層高度
- _popupWeight = popupName.width(); //獲取彈出層寬度
- // _posiTop = (_windowHeight - _popupHeight) / 2 + _scrollHeight - 50;
- _posiTop = _scrollHeight + 120;
- _posiLeft = (_windowWidth - _popupWeight) / 2;
- popupName.css({ "left": _posiLeft + "px", "top": _posiTop + "px", "display": "block" }); //設(shè)置position
- }
- function dragFunc(dragDiv, dragBody) {
- if (dragDiv[0] && dragBody[0]) {
- var dragAble = false;
- var x1 = 0;
- var y1 = 0;
- var l = 0;
- var t = 0;
- var divOffset = dragBody.offset();
- dragDiv.mousedown(function (e) {
- var ss = this;
- // var rootId =
- dragDiv.css("cursor", "move");
- dragAble = true;
- // 當(dāng)前鼠標(biāo)距離div邊框的距離
- // 當(dāng)前鼠標(biāo)坐標(biāo),減去div相對(duì)左邊的像素
- l = parseInt(dragBody.css("left"));
- t = parseInt(dragBody.css("top"));
- x1 = e.clientX - l;
- y1 = e.clientY - t;
- x1x1 = x1 > 0 ? x1 : 0;
- y1y1 = y1 > 0 ? y1 : 0;
- this.setCapture && this.setCapture();
- });
- dragDiv.mousemove(function (e) {
- if (!dragAble)
- return;
- // 當(dāng)前div左邊的坐標(biāo)
- // 當(dāng)前鼠標(biāo)坐標(biāo),減去鼠標(biāo)拖動(dòng)量
- var x2 = 0;
- var y2 = 0;
- //需要考慮滾動(dòng)條問(wèn)題?。?!
- var top = $(document).scrollTop() ? $(document).scrollTop() - 15 : 0;
- var left = $(document).scrollLeft() ? $(document).scrollLeft() - 15 : 0;
- x2 = e.clientX - x1 + left;
- y2 = e.clientY - y1 + top;
- x2x2 = x2 > 0 ? x2 : 0;
- y2y2 = y2 > 0 ? y2 : 0;
- //要移動(dòng)一定數(shù)量才移動(dòng)
- if (Math.abs(l - x2) > 10 || Math.abs(t - y2) > 10) {
- dragBody.css("left", x2 + "px");
- dragBody.css("top", y2 + "px");
- }
- });
- dragDiv.mouseup(function (event) {
- if (!dragAble)
- return;
- dragAble = false;
- // dragDiv.css("position", "relative");
- this.releaseCapture && this.releaseCapture();
- });
- }
- }
- var MyDialog = function (cfg) {
- this.config = {
- id: (new Date()).getTime().toString(),
- el: null,
- bodyId: null,
- cover: true,
- boxHtm: ''
- };
- var scope = this;
- if (cfg) {
- $.each(cfg, function (key, value) {
- scope.config[key] = value;
- });
- }
- this.box = null;
- this.cover = null;
- this.tmpBody = null;
- }
- MyDialog.prototype.show = function () {
- var scope = this;
- var cover = null;
- var box = null;
- if (this.config.cover) {
- if (this.config.id && $('#' + this.config.id + '_cover')[0]) {
- cover = $('#' + this.config.id + '_cover');
- cover.show();
- } else {
- cover = $('');
- $('body').append(cover);
- }
- scope.cover = cover;
- }
- if (!$('#' + this.config.id)[0]) {
- box = $(this.config.boxHtm);
- $('body').append(box);
- box.attr('id', this.config.id);
- if (this.config.title) {
- box.find('.title_text').html(this.config.title);
- }
- if (this.config.bodyId) {
- var body = $('#' + this.config.bodyId);
- var tmp = $('').append(body);
- var initBody = tmp.html();
- scope.tmpBody = $(initBody);
- tmp = null;
- if (body[0]) {
- var con = box.find('.main .content');
- body.show();
- con.html('');
- con.append(body);
- }
- }
- if (this.config.el && this.config.el[0]) {
- var con = box.find('.main .content');
- con.html(this.config.el);
- }
- //居中
- popup(box);
- //關(guān)閉dialog
- box.find('.title .cls').click(function (e) {
- scope.close();
- e.preventDefault();
- return false;
- });
- dragFunc($('#' + this.config.id + ' .main .title'), $('#' + this.config.id));
- box.show();
- this.box = box;
- }
- }
- MyDialog.prototype.close = function () {
- //這里有問(wèn)題
- var box = this.box;
- var tmpBody = this.tmpBody;
- var cover = this.cover;
- if (tmpBody && tmpBody[0]) {
- $('body').append(tmpBody);
- }
- if (box && box[0]) {
- box.remove();
- }
- if (cover && cover[0]) {
- cover.hide();
- }
- };
調(diào)用方法:
- var dia = new MyDialog({
- title : title,
- bodyId : id,
- id : id + '_box'
- });
- dia.show();
具體可能還需要一定函數(shù)回調(diào),各位可以自己封裝一番。
拖放
工作中也經(jīng)常會(huì)出現(xiàn)拖放效果的一些需求:
代碼如下:


咨詢
建站咨詢