开发者

Center an image in document [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. 开发者_Go百科 Closed 10 years ago.

Not even really sure what kind of title this question needs. Basically I have made a cheeky bit of JavaScript in jsFiddle and it works perfectly. Then I've popped on a test site and it doesn't work at all. I cannot figure out why at all and it's doing my head in.

Basically the code calculates the width of the image and uses this value to place the image in the center of the page. Works great on the window.resize but for some reason the document.load isn't working on the test server but it works fine in JS Lint. I've popped an alert in there as well for testing purposes.

jsFiddle Link: http://jsfiddle.net/sambeckhamdesign/4g4nD/49/


Load jQuery before your script and use your browser's error console

Uncaught ReferenceError: $ is not defined java.js:9


You've put your javascript method above the call to include jQuery.

At that point, jQuery hasn't been defined. Switch the lines so that jQuery is first.

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.6/jquery.min.js" type="text/javascript"></script>
<script src="/_js/java.js" type="text/javascript"></script>


you have

<script src="/_js/java.js" type="text/javascript"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.6/jquery.min.js" type="text/javascript"></script>

it should be

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.6/jquery.min.js" type="text/javascript"></script>
<script src="/_js/java.js" type="text/javascript"></script>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜