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