Create a Thumbnail with Fading Caption Using jQueryに記載されているプラグインを使用していますが、私のキャプションはh2
で、テキストはimg
attrから取得しますか?'img'タイトル属性を取得してh2に配置する方法は?
0
A
答えて
2
、代わりにプラグインの例を次のようにHTMLを行います
$(function() {
// let's set a variable as our img attr title
var title = $("img").attr('title');
var move = -15;
//zoom percentage, 1.2 =120%
var zoom = 1.2;
//On mouse over those thumbnail
$('.item').hover(function() {
//Grab title from title attr
$("h2").hide().append(title).fadeIn('slow');
//Set the width and height according to the zoom percentage
width = $('.item').width() * zoom;
height = $('.item').height() * zoom;
//Move and zoom the image
$(this).find('img').stop(false,true).animate({'width':width, 'height':height, 'top':move, 'left':move}, {duration:200});
//Display the caption
$(this).find('div.caption').stop(false,true).fadeIn(200);
},
function() {
//Remove title
$("h2").empty();
//Reset the image
$(this).find('img').stop(false,true).animate({'width':$('.item').width(), 'height':$('.item').height(), 'top':'0', 'left':'0'}, {duration:100});
//Hide the caption
$(this).find('div.caption').stop(false,true).fadeOut(200);
});
});
:
<div class="item">
<a href="link">
<img src="link img" title="your title" width="125" height="125"/>
<div class="caption">
<h2></h2>
</div>
</a>
</div>
が、これは説明するためのコメントで、あなたが必要とする更新jQueryのです
1
alt
属性を取得し、キャプションHTMLに挿入します。そのプラグインのコードに従うことにより
$('#captionID').html($('#imageID').attr('alt'));
+0
を投稿 –
0
これを使用してください。
$('#imgSelector').attr('title')
または
$('#imgSelector').attr('alt')
関連する問題
- 1. Pythonでアンカータグのタイトル属性のテキスト値を取得する方法は?
- 2. Python:getattrを使ってオブジェクトの属性の属性を取得する方法は?
- 3. employeeid属性を取得する方法
- 4. AngularJSで配列の属性の値を取得する方法
- 5. ノードred配列jsonで属性を取得する方法
- 6. mp3ファイルの「タイトル」と「作成者」の属性を取得する方法
- 7. javascriptを使用してHTMLのimgタイトル属性を設定する
- 8. img属性を取得して文字列に追加します
- 9. JQueryがimg srcを取得し、データ属性として使用する
- 10. 「データ」属性の取得方法は?
- 11. reStructuredTextの属性の取得方法は?
- 12. XMLにLinqを使用してXML属性値を取得する方法は?
- 13. activerecordハッシュに合成属性を取得する方法は?
- 14. イメージタグからwidth属性とheight属性を取得する方法は?
- 15. 列挙型モデル属性の配列を取得する方法は?
- 16. 'NoneType' オブジェクトには、属性 'タイトル'
- 17. ワードプレスギャラリー画像のメタ属性(タイトル、代替、...)を取得するには?
- 18. swfobject:オブジェクトにHTMLタイトル属性を追加する方法(フラッシュ)
- 19. タイトル属性に動的データを適用する別の方法
- 20. simpleHTMLDomを使用してhtmlタグの属性値を取得する方法は?
- 21. VB.NETを使用してXMLから属性値を取得する方法は?
- 22. JavaScriptを使用してHTMLでlang属性を取得する方法は?
- 23. すべてのワードプレスカテゴリidsを取得し、html属性に印刷する方法
- 24. Meteorユーザープロファイル属性の値を取得する方法は?
- 25. jQueryでHTML属性値を取得する方法は?
- 26. ASP.NETコードビハインドでバリデータのcontroltovalidate属性を取得する方法は?
- 27. SQLAlchemy:grandparent属性をgrandparentから取得する方法は?
- 28. data-esid属性とPOSTを取得する方法は?
- 29. ユーザー名などのユーザーセッション属性を取得する方法は?
- 30. 階層URIで属性を取得する方法は?
まあ、彼はそれがH2にする必要があなたのコード... –