首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >SimpleModal OSX样式

SimpleModal OSX样式
EN

Stack Overflow用户
提问于 2010-08-02 19:05:44
回答 1查看 1.4K关注 0票数 0

目前,我有以下代码:

代码语言:javascript
复制
  <!-- modal content -->
  <div id="osx-modal-content-1">
   <div id="osx-modal-title">OSX Style Modal Dialog</div>
   <div class="close"><a href="#" class="simplemodal-close">x</a></div>

   <div id="osx-modal-data">
    <h2>Hello! I'm SimpleModal!</h2>
    <p>SimpleModal is a lightweight jQuery Plugin which provides a powerful interface for modal dialog development. Think of it as a modal dialog framework.</p>
    <p>SimpleModal gives you the flexibility to build whatever you can envision, while shielding you from related cross-browser issues inherent with UI development..</p>
    <p>As you can see by this example, SimpleModal can be easily configured to behave like an OSX dialog. With a handful options, 2 custom callbacks and some styling, you have a visually appealing dialog that is ready to use!</p>
    <p><button class="simplemodal-close">Close</button> <span>(or click the overlay)</span></p>

   </div>
  </div>


jQuery(function ($) {

 var OSX = {
  container: null,
  init: function () {
   $("area.osx, input.osx, a.osx").click(function (e) {
    e.preventDefault(); 

    $('#osx-modal-content-' + this.title).modal({
     overlayId: 'osx-overlay',
     containerId: 'osx-container',
     closeHTML: null,
     minHeight: 80,
     opacity: 65, 
     position: ['0',],
     overlayClose: true,
     onOpen: OSX.open,
     onClose: OSX.close
    });
   });
  },
  open: function (d) {
   var self = this;
   self.container = d.container[0];
   d.overlay.fadeIn('slow', function () {
    $("#osx-modal-content-" + this.title, self.container).show();
    var title = $("#osx-modal-title", self.container);
    title.show();
    d.container.slideDown('slow', function () {
     setTimeout(function () {
      var h = $("#osx-modal-data", self.container).height()
       + title.height()
       + 20; // padding
      d.container.animate(
       {height: h}, 
       200,
       function () {
        $("div.close", self.container).show();
        $("#osx-modal-data", self.container).show();
       }
      );
     }, 300);
    });
   })
  },
  close: function (d) {
   var self = this; // this = SimpleModal object
   d.container.animate(
    {top:"-" + (d.container.height() + 20)},
    500,
    function () {
     self.close(); // or $.modal.close();
    }
   );
  }
 };

 OSX.init();

});

但是当我启动对话框时,它并没有填充内容。

一定是个简单的错误,但我找不到

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2010-08-03 04:15:23

在"open“函数中,引用了"this.title”

我不是javascript专家,但我相信一旦你离开了" click“函数,你就会失去"this”的上下文(除非你是在click函数中声明/创建这个函数)。

因此,当您调用以下代码时:

代码语言:javascript
复制
d.overlay.fadeIn('slow', function () {
                        $("#osx-modal-content-" + this.title, self.container).show();

this.title返回"“

如果你硬编码"#osx-modal-content-1",你会发现它是有效的

代码语言:javascript
复制
d.overlay.fadeIn('slow', function () {
                        alert(this.title);
                        $("#osx-modal-content-1" , self.container).show();
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/3387104

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档