最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - dojo show() and hide() porting from jquery() - Stack Overflow

programmeradmin2浏览0评论

I am just porting a bunch of code from jQuery to DOJO (1.8). I was stumbling upon show/hide of DOM elements (may it be layers or anything else).

Let's say we have a layer that we want to show or hide, without animation. Imagine a Buttonbar that changes on some event, I don't necessarily want to bring in graphical effects all the time.

<div id="myLayer">hide me</div>

In jQuery I would do:

$("#myLayer").show();  // to show
$("#myLayer").hide();  // to hide

which I find very nice and slim. Now porting to DOJO I found that I need to do the following:

require(["dojo/fx/Toggler"], function(Toggler) {
    // Create a new Toggler with default options
    var toggler = new Toggler({
      node: "myLayer",
      hideDuration: 0,
      showDuration: 0
    });

    // Hide the node
    toggler.hide();

    // Show the node
    toggler.show();
  });

That's 8 lines of code versus 2 lines of code. Am I missing something? Is there any faster way to do a simple hide?

Thanks a lot, Tobi

I am just porting a bunch of code from jQuery to DOJO (1.8). I was stumbling upon show/hide of DOM elements (may it be layers or anything else).

Let's say we have a layer that we want to show or hide, without animation. Imagine a Buttonbar that changes on some event, I don't necessarily want to bring in graphical effects all the time.

<div id="myLayer">hide me</div>

In jQuery I would do:

$("#myLayer").show();  // to show
$("#myLayer").hide();  // to hide

which I find very nice and slim. Now porting to DOJO I found that I need to do the following:

require(["dojo/fx/Toggler"], function(Toggler) {
    // Create a new Toggler with default options
    var toggler = new Toggler({
      node: "myLayer",
      hideDuration: 0,
      showDuration: 0
    });

    // Hide the node
    toggler.hide();

    // Show the node
    toggler.show();
  });

That's 8 lines of code versus 2 lines of code. Am I missing something? Is there any faster way to do a simple hide?

Thanks a lot, Tobi

Share Improve this question edited Mar 10, 2013 at 16:56 frenchie 52.1k117 gold badges320 silver badges528 bronze badges asked Mar 10, 2013 at 16:54 Tobias N. SasseTobias N. Sasse 2,5671 gold badge20 silver badges14 bronze badges 2
  • 1 please see this question , but before you go any further with dojo if your aim is some dom manipulation then it's not the place to go (they wouldnt have created it , if it was the same thing ) please read more on when to chose dojo for your project , this is just a small tip :) – Hussein Nazzal Commented Mar 10, 2013 at 17:00
  • I am doing a lot of AJAX based WebUI stuff in my application. I found it quite handy to bine different functionality within one (jsp) view, without having to switch pages (and in the MVC pattern also controller and stuff behind) for simple tasks. Thus I believe having a solid JavaScript Framework in hand is good practice. As a side effect DOM manipulation es with it of course. I found that quite easy in jQuery but am stuggeling with dojo though... perhaps there is something wrong in my general approach. – Tobias N. Sasse Commented Mar 10, 2013 at 17:09
Add a ment  | 

1 Answer 1

Reset to default 6
require(["dojo/query", "dojo/NodeList-dom", "dojo/domReady!"], function(query){
  query("#myLayer").style("display", "none");
});
发布评论

评论列表(0)

  1. 暂无评论