jquery drag image

前端 未结 5 398
感动是毒
感动是毒 2021-01-11 19:17

i want to make a draggable image in jquery. first of all my experience with jquery is 0. having said that let me describe what i want to achieve. i have fixed width/height

5条回答
  •  不思量自难忘°
    2021-01-11 19:56

    You want the jQuery Draggable UI tool. The code for this, as with all jQuery, is very simple:

    $(document).ready(function(){
      $("#draggable").draggable();
    });
    

    Will create a draggable object from a standard html tag (the IMG in your case). And for limiting it's mobility to a specific region, you would look into its containment option.

    Update: "What is '#draggable' and 'ready'"?

    1. '#draggable' represents the element that you want to be able to drag. The hash (#) symbol represents an ID. When you add your image tags, may give give it an id like the following:



      That will make the javascript above make your image draggable, because it has the '#draggable' id that the jQuery is looking for.
    2. '.ready()' is the method that is automagically raised by your browser once the page is finished loading. Developers are encouraged by the jQuery group to place all jQuery code within this method to ensure all of the elements on the page are completely loaded prior to any jQuery code attempts to manipulate them.

自定义标题
段落格式
字体
字号
代码语言
提交回复
热议问题