How to add similar __public__ picture path in thinkphp about JS file

Source: Internet
Author: User

In the optimization of HTML style, often use js/jquery to do some jump switch style, and what we often do is to embed the URL image link code in the Js/jquery code, in order to achieve dynamic interactive page effect.

As shown in the following:

--------------------------------------------------------------------------------------------------------------- ----------------

Problem: JS file does not know __public__ these thinkphp unique links, so we have to redefine the URL address ourselves to use these paths.

In addition, the definition URL can not be in the JS file, must be in the JS file corresponding to the index.html code to write only effect! In general, the imported JS file is placed under the definition URL address, so that you do not have to worry about the introduction of JS file when you cannot use the defined URL path.

Workaround:

First step: Define the URL path in the index.html page

<Script>     var  url  = "__public__/home"; //define the URL path in JS</Script>
<Scriptsrc= "__public__/home/js/cy.js"></Script>

The second step: reference the defined URL, so that the perfect in the thinkphp to identify the image URL path in JS

function figureanimate (obj) {    $figureImg. addclass (' amimatezoom '). Animate ({opacity:0,right: ' -300px '},200, function () {        $figureImg. attr (' src ',url + '/img/' +obj.img). Removeclass (' amimatezoom ')// Simple character conversion src address        . Animate ({opacity:1,right: ' -150px '},200);                $ ('. Readstar '). attr (' Data-url ', obj.url);        $figureText. HTML (obj.html);        $figureName. Text (obj.name);    });

Mistakes, but also look at the correct!

How to add a __public__ picture path to a JS file in thinkphp

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.