Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
I've a views displaying some fields of a content type among them there is an image field.
I want to add some custom JS annimation my image field with no result.
What i did so far:
create a MyJsFile.js in my theme (in the sub-bootstrap 3 theme .js folder)
i added this function to my js file (found here):
<?php
function MyTheme_preprocess_views_view(&$vars) {
$view = $vars['view'];
// Make sure it's the correct view
if($view->name == 'event_front') {
// add needed javascript
drupal_add_js(drupal_get_path('theme', 'MyTheme') . '/js/MyJsFile.js');
}
}
?>
But it's not working. When i hover over the image, nothing happend. And i can log my js file with the comment console.lo
have no idea how to that with drupal.
Does anyone have any idea how to achieve this?
Comments
Comment #2
silvi.addweb CreditAttribution: silvi.addweb at AddWeb Solution Pvt. Ltd. commentedI tried as per your comment and it worked proper here. So can you please elaborate the issue in detail and give me your js code.
Further, do check js name if it is found on view source of the page.
Thanks!
Comment #3
dynahiol CreditAttribution: dynahiol commentedThanks for your replay tejal.patel
this is my js code:
The preprocess_views function was added to my template.php file. I can't see the js file name on the browser when checking for js file.
Comment #4
silvi.addweb CreditAttribution: silvi.addweb at AddWeb Solution Pvt. Ltd. commented@dynahiol, That works fine from my end but you can check the following different ways incase of a minute miss. :)
1. Please check the below code, does that incorporates 'if condition'.
2. Please call js using inline code:
3. In your js code. You are using .load() function as per my understanding in jquery selectopr is "Id" or "Class" so you need to set prefix "#" or ".".
I hope it helps you.
Thanks!
Comment #5
dynahiol CreditAttribution: dynahiol commented@tejal.patel thanks for your help. I've change my code accordingly. And the MyTheme_preprocess_views_view function is working fine.
But i still can't get my js to run. I've tried several code. But still no convincing result. I also found out that my view name was wrong.
This funtion is working.
But the js file is still not being call (i've change the selector too). Check out the codes below:
Or
Found here
Both js code are not working. Do have any idea why?
Comment #6
MustangGB CreditAttribution: MustangGB commentedClosing this as outdated to tidy up a bit around here. If you're still having problems with the latest release please create a new issue.