Home > Web Front-end > JS Tutorial > body text

Simplified version of mobile phone photo preview component_javascript skills

WBOY
Release: 2016-05-16 16:04:39
Original
1159 people have browsed it

Poor, I use a Huawei 3C mobile phone, and it’s easy to use other people’s ready-made components. In order to adapt to a loser like me, I simplified and wrote a version of the photo preview effect. There is no zoom function for the time being. I may try it again when I have time. Add it, you can also add it yourself, this is an open source project on github. Its github address is: https://github.com/tianxiangbing/mobile-photo-preview

The following is a preview,

Usage examples:

var photoPreview = new MobilePhotoPreview();
    photoPreview.init({
      target: $('.preview-list'),
      trigger: '.preview',
      show: function(c) {
        var del = $('<span class="icon-del"><span>');
        $('.imgViewTop', c).append(del);
        del.tap(function() {
          photoPreview.current.remove();
          photoPreview.hide();
        });
      }
    });
Copy after login

or:

$('.preview-list').MobilePhotoPreview({
      trigger: '.preview',
      show: function(c) {
        var del = $('<span class="icon-del"><span>');
        $('.imgViewTop', c).append(del);
        var _this = this;
        del.tap(function() {
          _this.current.remove();
          _this.hide();
        });
      }
    });
  
Copy after login

Note: There is no essential difference between the two methods. The first one is recommended.

API properties, methods and callbacks:

target:
It means that the elements in this container will trigger the event. It is a range and is used together with trigger to delegate the event node, so it is necessary. It is recommended not to delegate the root node.
trigger:
Represents the object that triggers the event. It can be dynamic. By default, it is triggered by a link under the target
show:
The callback after display, the parameter is the dialog container, and this currently points to the instance of MobilePhotoPreview. This is a callback method to extend more functions. In order to better use this callback, you may be interested in the following properties
Properties and methods under this:
current:
Current node object
currentIndex:
Current index
objArr:
Array object, here, you can get a collection, including index, element, width, and height. This will be very useful stuff.
hide:
What is called is the hide.

of dialog

The above is the entire content of this article, I hope you all like it.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template